Interface vs. Abstract class

V

Valmont

Moving from C++ to C# .Net:

Why does an interface exist in C# when I can create one by making all methods in
the abstract class "pure virtual"?
Did I miss something conceptually or is the "interface" just here for my
conveniance?
If it is a convinient thing, what style is accepted by the C# community (or mcsd
requirements) as the standard?
 
B

Barry Kelly

Valmont said:
Moving from C++ to C# .Net:

Why does an interface exist in C# when I can create one by making
all methods in the abstract class "pure virtual"?

Because .NET doesn't support multiple inheritance.
Did I miss something conceptually or is the "interface" just here for my
conveniance?
If it is a convinient thing, what style is accepted by the C# community (or mcsd
requirements) as the standard?

Interfaces are also useful in their own right, since the notion of a
stateless "supports" relationship is distinct from a class-based "is-a"
relationship.

Interfaces also have downsides that make abstract base classes
preferable in many situations - I made a post in this group a few days
ago in response to Jon Skeet listing some of them.

-- Barry
 
V

Valmont

"Barry Kelly" <[email protected]> schreef in bericht
|
| > Moving from C++ to C# .Net:
| >
| > Why does an interface exist in C# when I can create one by making
| > all methods in the abstract class "pure virtual"?
|
| Because .NET doesn't support multiple inheritance.

| Interfaces are also useful in their own right, since the notion of a
| stateless "supports" relationship is distinct from a class-based "is-a"
| relationship.
|| -- Barry
|
| --
| http://barrkel.blogspot.com/


Oh I see now. Thank you for your very fast response.
 
S

Sericinus hunter

Valmont said:
Moving from C++ to C# .Net:

Why does an interface exist in C# when I can create one by making all methods in
the abstract class "pure virtual"?
Did I miss something conceptually or is the "interface" just here for my
conveniance?

You cannot inherit from multiple classes in C#, but
you can implement multiple interfaces.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top