views:

940

answers:

4

I am wondering if there are any differences to derived classes when using abstract vs real classes for inheritance?

It looks to me like the real class inheritance creates an hierarchy whereas abstract class inheritance is just copy-paste code for the compiler to derived classes?

Does the abstract class creates a hierarchy? Can it be accessed using a special keyword?

I know that you use the base keyword to access the base class, but abstract members look just like the original members in the derived classes?

Lastly what's the performance difference between the 2?

+4  A: 

Yes the abstract class does exist - the compiler does not do a copy-paste. You will not find any performance difference though as the CLR must still do virtual method calls.

For example the following C#:

abstract class Foo { }

class Bar : Foo { }

generates the following IL:

.class private abstract auto ansi beforefieldinit Foo
    extends [mscorlib]System.Object { }

.class private auto ansi beforefieldinit Bar
    extends Foo { }

The concept of an abstract type is very much a part of the IL.

Andrew Hare
+2  A: 

The only difference is that an abstract base class cannot be instantiated without being derived from, whereas a non-abstract one can. From the point of view of a derived class, everything is the same.

Greg Beech
+1  A: 

Try this answer

A: 

The power of abstract class is in it unimplementation. It can be used for confidence that instance of derived classes will have the full needed functionality

Yuriy Vikulov