Abstraction


What if we were writing code as part of a large project having many contributors and we wish to ensure that the contributors conform to a defined interface?

A realistic example might be a large graphics library where we might expect a large number of graphics objects (e.g shapes) all of which must support a certain set of operations (translations, rotations, output...).


Abstract classes allow us to enforce a common interface without specifying the implementation.
class shape
{
public:

   virtual move( vector ) = 0;
   virtual rotate( angle ) = 0;
   virtual draw() = 0;
}

We require all contributors to derive realistic shapes (squares, circles etc.) from the shape class. The compiler will reject attempts to create a circle unless circle has implementations for move(), rotate() and draw().