What is the advantages of using Interface in OOP? Please give an example using Interface to clarify that using Interface is better than one without interface.
Printable View
What is the advantages of using Interface in OOP? Please give an example using Interface to clarify that using Interface is better than one without interface.
Implementing an interface offers advantages in certain circumstances. One advantage is that it allows you to take a number of different types, that may be quite different in some regards, and treat them in the same way. An example would be the DataGrid.DataSource property, which will accept any component that implements either the IList or IListSource interface. This means that you can create a class with whatever functionality you like but as long as it implements one of those interfaces you can bind it to a DataGrid.
An interface provides a common (if perhaps partial) specifiction for a class. You can rely on the fact that all classes that implement that interface will have the same methods as defined in the interface, even if they behave differently.
Another example is plugins, if you design an common interface for an application plugin you can specify plugins using that interface, regardless of what the plugin actually does.
I want to ge more ideas about Interface. Need help.
Interface
Interface (Computer Science) - this is probably what you're looking for ;)
User Interface
Read this and follow the relevant links at the bottom, which really gives you all you need to know about interfaces as they relate to VB.NET: http://msdn.microsoft.com/library/de...BSpec6_7_1.asp
Things are pretty much the same in C#.