interfaces and abstract classes

  • Thread starter Thread starter ichor
  • Start date Start date
I

ichor

what is hte difference between the 2?
i am reading wrox professional c# and fail to understand the difference
between teh 2?
 
what is hte difference between the 2?

An abstract class can have data fields and non-abstract members, an
interface can't.

A class can derive only from a single class, but implement multiple
interfaces.



Mattias
 
In addition to what Mattias said, there is a real conceptual
difference between the two. An abstract class forms the base for an
"is a " relationship, while an interface is a role an object takes
on.

e.g., a door is a "WoodenObject", and it operates in the role of a
"Lockable" device. A window also takes on the same role, but is not
a WoodenObject.

You could use an interface where an abstract class is more appropriate
and make it work, but it would be confusing to others. Take a look
at the interfaces defined within .NET and you'll see that they are
roles, not base identities.
 
thanx doknjas..
what u say makes so much sense..
i would like to delve deep into object oriented c# ..
are there any good resources i can look at..
including buying good books

thanx

Doknjas said:
In addition to what Mattias said, there is a real conceptual
difference between the two. An abstract class forms the base for an
"is a " relationship, while an interface is a role an object takes
on.

e.g., a door is a "WoodenObject", and it operates in the role of a
"Lockable" device. A window also takes on the same role, but is not
a WoodenObject.

You could use an interface where an abstract class is more appropriate
and make it work, but it would be confusing to others. Take a look
at the interfaces defined within .NET and you'll see that they are
roles, not base identities.
 
I've found "Programming C#" by Jesse Liberty (published by O'Reilly)
quite useful.

I also use Instant C# (www.instantcsharp.com) to convert VB code to
C#, since I have a lot of VB production and sample code sitting
around, being a VB programmer for 10 years. Also, when I dig up an
example in VB, I don't have to waste time looking for the C# version.
 
Back
Top