Update of "Capability Classes"
Not logged in
Overview

Artifact ID: fcf3bab66508de73615085537de9d86462e03768
Page Name:Capability Classes
Date: 2013-01-07 21:50:36
Original User: Les Farrell
Parent: 6ff3cdabceffae5db90639151e862ec1a28d0c7e (diff)
Content

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.