من قبل
Hussein Fareed , BI and Data Warehouse Supervisor , TE Data
Interfaces are mostly used to define a capability of a class in order to behave consistently. For example, a class may inherit an interface (IEnumerable) which specifies that this class can be used in a foreach loop. As mentioned above in Nahjmal's answer, one of the main distinctions between interfaces and classes is the ability of multiple inheritance. Multiple inheritance is prohibited in C# using classes unlike C++ so interfaces gives you the ability to simulate this ability.
Interface helps to design loosely coupled architecture. It allows us to connect with different implementation of class, in different environment (i.e., Test, Development, Production). If we directly use class instant. Design gets rigid for further extending of the application, etc.
من قبل
Najmal Karuthedath , Dot Net Developer , Dicetek
Interface is a contract that defines the signature of the functionality. So if a class is
implementing a interface it says to the outer world, that it provides specific behavior.
Example if a class is implementing Idisposable interface that means it has a functionality
to release unmanaged resources. Now external objects using this class know that it has
contract by which it can dispose unused unmanaged objects.
Interface helps to implement multiple Inheritance in .NET framework.
من قبل
karim kamel , Developer Support Engineer , Microsoft
Purposes of Interfaces
create loosely coupled software
support design by contract (an implementor must provide the entire interface)
allow for pluggable software
allow different objects to interact easily
hide implementation details of classes from each other
facilitate reuse of software