Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
In C# an abstract class is one that does not provide implementations for all its methods. A class must be declared abstract if any of the methods in that class are abstract. For example, the GraphicalObject class defined in Program is declared abstract because its Draw method is abstract.
An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implementations for the methods that are not implemented in the base class. A derived class that implements all the missing functionality is called a concrete class .
In C# it is not possible to instantiate an abstract class. For example, the following declaration is illegal:
GraphicalObject g = new GraphicalObject(new Point(0,0)); // Wrong.If we were allowed to declare g in this way, then we could attempt to invoke the non-existent method g.Draw().