• Post Reply Bookmark Topic Watch Topic
  • New Topic

uses of interface  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the uses of interface other than multiple inheritance..and is there any specific reason for the name interface
[ March 26, 2008: Message edited by: mari maris ]
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, just a couple of opinions I would throw in.

Using interfaces allows you to define the characteristics of a particular API that you wish to design. That API can then be implemented by whatever different classes you might need to design. Having your classes implement the interface in this manner gives you at least these benefits:

1) The API can be tightly defined in one place. This means that, as you work on the API, you make the changes in one place and all of your classes get the change when recompiled.

2) With polymorphism in mind, you can design methods that specify the interface as their parameter type. That way, other code that calls into this method can pass any of the object types that implement the interface, and it will be able to accept them.

3) Another benefit that goes along with number 2 is that doing this helps provide lower coupling. Since the interface type only defines the API methods, the methods of the implementing classes are not available using the interface reference. The only methods that can be called (without doing any re-casting) are the methods defined by the interface.

That was just my impression.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!