Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.35/5 (9 votes)
See more:
what is Interface in C# and why we are using interface in C# application and real time example for this...........
Posted

interface (C# reference)[^]
Interfaces (C# Programming Guide)[^]
The Interface Construct in C#[^]
Interfaces in C# (For Beginners)[^]
I, Interface[^]

And as a bonus:
Abstract Class versus Interface[^]

Amazing what a bit of Googling can do :)
Hope it helps. If you still have any questions in particular after reading ALL those articles feel free to ask again :)
 
Share this answer
 
What does an interface do?[^]

Hope it helps :)
 
Share this answer
 
An interface looks like a class, but has no implementation.
-The only thing it contains are declarations of events, indexers, methods and/or properties.
-The reason interfaces only provide declarations is because they are inherited by classes and structs, which must provide an implementation for each interface member declared.

Interfaces in C# are provided as a replacement of multiple inheritance.
-Because C# does not support multiple inheritance, it was necessary to incorporate some other method so that the class can inherit the behavior of more than one class, avoiding the problem of name ambiguity that is found in C++.
-With name ambiguity, the object of a class does not know which method to call if the two base classes of that class object contain the same named method.

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

Details of C# interfaces[^] -- With C#/OOP interfaces you're doing the same kind of thing but in the unseen/virtual world.

Also refer similar discussion on: Why we use Interface?[^]

Please refer some links for real time examples:
Real Time example for Interface[^]
Real world examples of abstract classes and interfaces?[^]
Real World Interfaces in C#[^]
 
Share this answer
 
Comments
Sander Rossel 28-May-12 6:09am    
How do Interfaces replace multiple inheritance? With such logic you could argue that inheriting from a base class is the same as implementing an interface. Which is not quite the case.
I might have misunderstood your answer at that point. Other than that good answer. My 5.
BobJanova 28-May-12 6:12am    
I offered a 4 because of the confusing part about multiple inheritance. Interfaces don't replace MI; they provide a method of specifying multiple required behaviour, but not one for -inheriting- that behaviour.

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