Artifact [fcf3bab665]
Not logged in

Artifact fcf3bab66508de73615085537de9d86462e03768:

Wiki page [Capability Classes] by Les Farrell 2013-01-07 21:50:36.
D 2013-01-07T21:50:36.587
L Capability\sClasses
P 6ff3cdabceffae5db90639151e862ec1a28d0c7e
U Les\sFarrell
W 1048
<b>Capability Classes</b> [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 <b>Bird</b> 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 <b>void</b> to <b>int</b> 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 <b>#include</b> directives but it is important to <b>#include</b> the base class before the derived classes to avoid a compiler error.

Z 1e627e2ac18d0be36d6ae3654e0e54c8