This syntactic element is common to most early-binding object-oriented computer programming
languages such as C++
An abstract class, often also called an abstract base class, is a class that cannot be instantiated due to the presence of one or more virtual functions that are declared but not implemented by the class, ie pure virtual methods. It's a way of telling yourself: Do not create create instances of this class, subclass it.
, both classes and method
s can be declared
, for e.g.
abstract class Polygon
abstract public double getArea();
(as with C++
) methods can be declared abstract, and any class with abstract methods is an abstract class. for e.g.:
TPolygon = class(TObject)
function GetArea: double; virtual; abstract;
See the other writeups for a C++ example. My C++ is too rusty, sorry.
But why would you want to do this?
A abstract method is a placeholder for functionality that the child class must fill in if it is to be concrete
Making the method abstract says explicitly that the class is too generic to give a reasonable default implementation for the abstract method, and that all concrete child classes must override it in thier own way.
A base class that is intended only for subclassing and not for direct use defines an interface contract that is shared by all of its child classes.
However, calling code can deal with an object that appears to be of the base type, and does not need to know how the method is implemented by the particular child class. Thus the calling code deals only with the interface contract defined by the base class.