Results 1 to 5 of 5

Thread: interface

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Answers
    14

    interface

    What is use of interface? Why we actually use it?


  2. #2
    Junior Member
    Join Date
    Jan 2007
    Answers
    15

    Re: interface

    Interface is actually 100% abstract class whose all the methods have only definition not body. if your class implements any interface then provide body for all the methods.

    actually java doesn't support multiple inheritence means ur class cant inherit(extends) more than 1 class. but if u want to inherit more than one class then use Interface.

    actually we achieve multiple inheritance by Interface.


  3. #3
    Expert Member
    Join Date
    May 2009
    Answers
    1,374

    Re: interface

    Quote Originally Posted by ashina1111 View Post
    What is use of interface? Why we actually use it?

    Hi Ashina111,

    1) In the concept of data hiding , let's say you want to provide a class to some client code, but don't want to give them full access.

    One way to restrict access without limiting the functionality of your class is to implement an interface and require the client code to get objects through a factory:

    2)Another benefit of interfaces is team development.

    If you have a dozen programmers working on different pieces of code that need to connect, it's best to define interfaces for the connections. As long as the programmers write according to the interfaces, everything will link together nicely regardless of personal choices and style.

    3)Yet another benefit is that with interfaces you can use a class without having defined it first.
    Eg:

    If you have a class that does a lot of intricate work and won't be finished before the rest of the project, the rest of the project can use an interface to it and avoid being stalled by the development of that one class.

    I think its enough to resolve ur query.

    Thanks,
    Riju.


  4. #4
    Junior Member
    Join Date
    May 2010
    Answers
    6

    Re: interface

    Some times there will be a situation that most of the classes in our application has to implement the same set of methods.so instaed of writing all methods in each class we can write an interface and the classes will implement that interface to override all methods of interface.In .net a class can inherit only a single class but more than one interface.Indirectly multiple inheritence is supported in .net by Interface.Interface should contain public abstract members only.


  5. #5
    Junior Member
    Join Date
    Mar 2010
    Answers
    1

    Re: interface

    Another main use of interface in oops concept that we can implement more than one interface into one class but during expose, we can expose methods separetly by using Interface. Best example of this, to expose service in WCF, because we can make seperate interface for different module but we can implement all the methods in one class. Using interface we can allow to execute limited methods of any class.


  6.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact