Capability Classes
Not logged in

Capability Classes [1993b37ba2]

Classes whose sole purpose is to allow other classes to be derived from them are know as 'capability classes' - they provide capabilities to their derived classes.

Capability classes generally contain no data but merely specify a number of virtual methods that can be overridden in their derived classes.

The following example builds on the previous example to demonstrate how the Bird class can be better written as a capability class. Its methods no longer contain default output statements but a -1 (error) value if they are called explicitly.

It is necessary to change the return type of thoses methods from void to int and these changes must be reflected in each overriding method in the derived classes.

The base class and each derived class are now contained within their own header file. These are added to the main program with #include directives but it is important to #include the base class before the derived classes to avoid a compiler error.