Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is the need of use interface in c#

What I have tried:

what is the need of use interface in c#
Posted
Updated 16-May-16 19:11pm

Interfaces allow you to swap out specific implementations without changing the overall structure of your application.

The details of which may be radically different but to the calling code it stays the same, like Save() which could be a file save or dropbox save etc. which have different implementations.
 
Share this answer
 
Interfaces provides flexibility, we can define a single implementation that can implement multiple interfaces. when you want to inherit implementation from a base class it is a good choice to use Interface
In short it provides loose coupling, component-based programming, easier maintainability, makes your code base more scalable and makes code reuse much more accessible because implementation is separated from the interface, Interfaces add a plug and play like architecture into your applications.

Lets take example of vehicles, in that some are 4 wheeler, some are two but the common things is that each vehicles wheel are round shape, all are moving so these similar property we can keep in an interface and can inherit them for 4 wheeler and 2 wheeler also.
 
Share this answer
 
Don't forget that C# doesn't support multiple inheritance, so this is implemented with interfaces.

C# - Inheritance[^]

That was my one cent to the topic.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900