Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
Please let me know why do we need interface with simple example...as
i really didn"t get when to use it....how does it makes difference..
Posted 10-Mar-11 18:44pm
siva455811
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Interfaces in C# (For Beginners)[^]article from CP might help you.
  Permalink  
Comments
pradeep455 at 11-Mar-11 1:05am
   
thanks for your answer but the article specifies how to use interface but not when to use and how does it makes difference...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

See this discussion: When we use abstract and when we use interface...?[^].
 
Interesting article on the how interfaces a valuable: Using C# Interfaces to Make Applications Resilient to Changes[^].
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Because C# is an Object Oriented Programming language. Interface is an important OOP entity, see, for instance: "Interfaces in Object Oriented Programming Languages"[^].
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

You shouldn't ask why do we need interfaces
but when do we need interfaces.
 
You can code without interfaces, but if you whant to make some behaviour generic you can use interfaces to code better.
 
i think you should also read about the differences between interfaces and abstract classes
interface-vs-abstract-class-general-oo[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Multiple inheritance is not supported in C#. but it can be achieved using interfaces...
  Permalink  
Comments
CHill60 at 2-Jul-14 9:41am
   
Hm ... not sure I would accept that statement without details of how it could be achieved. However, the post is over 3 years old and already adequately answered. This adds nothing to the answers already posted.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

	
 
You can implement multiple interfaces, but only inherit from one abstract class.
 
An interface is an empty shell, there are only the signatures (name / params / return type) of the methods. The methods do not contain anything. The interface can't do anything. It's just a pattern
 
Abstract classes, unlike interfaces, are classes. There are more expensive to use because there is a lookup to do when you inherit from them.
 
Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 640
1 OriginalGriff 431
2 Maciej Los 255
3 PIEBALDconsult 180
4 Bruno Sprecher 170
0 Sergey Alexandrovich Kryukov 11,069
1 OriginalGriff 5,743
2 Maciej Los 5,649
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web02 | 2.8.141030.1 | Last Updated 22 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100