|
Inheritance vs Interface Polymorphism (C++)
Doxygen docs for the C++ implementation
|
#include <iostream>
Go to the source code of this file.
Classes | |
| class | Animal |
| Base class exposing a virtual speak() method. More... | |
| class | Dog |
| Animal subclass that overrides speak() to bark. More... | |
| class | Cat |
| Animal subclass that overrides speak() to meow. More... | |
| class | AbstractAnimal |
| Abstract base class combining shared state, a concrete default method, and a pure virtual method subclasses must implement. More... | |
| class | DogWithDefault |
| Concrete AbstractAnimal that implements the required speak() method. More... | |
| class | ISpeaker |
| Pure abstract class acting as an interface contract. More... | |
| class | InterfaceDog |
| ISpeaker implementation that barks. More... | |
| class | InterfaceCat |
| ISpeaker implementation that meows. More... | |
| class | ISingleSpeaker |
| Interface contract for a single, non-substitutable speaker. More... | |
| class | PureBreedDog |
| Sealed 'final' class ensures NO other subclass can modify this method path. More... | |
Functions | |
| void | makeSpeak (Animal &a) |
| Dynamic Dispatch via Class vtable. | |
| void | makeSleep (AbstractAnimal &aa) |
| Dynamic Dispatch using abstract parent reference. | |
| void | makeSpeak (ISpeaker &s) |
| Contractual Dispatch via Dynamic vtable Lookups. | |
| void | directSpeak (PureBreedDog &explicitDog) |
| Scenario A: Monomorphic target explicitly declared by final type reference. | |
| int | main () |
| Entry point exercising all four polymorphism scenarios. | |
| void directSpeak | ( | PureBreedDog & | explicitDog | ) |
Scenario A: Monomorphic target explicitly declared by final type reference.
| explicitDog | Reference to the concrete, non-overridable PureBreedDog type. |
Definition at line 172 of file C++ Implimentation.cpp.
| int main | ( | ) |
Entry point exercising all four polymorphism scenarios.
Definition at line 180 of file C++ Implimentation.cpp.
| void makeSleep | ( | AbstractAnimal & | aa | ) |
Dynamic Dispatch using abstract parent reference.
| aa | Reference to an AbstractAnimal; sleep() is a non-virtual, inherited default method shared by every subclass. |
Definition at line 96 of file C++ Implimentation.cpp.
| void makeSpeak | ( | Animal & | a | ) |
Dynamic Dispatch via Class vtable.
| a | Reference to a base Animal; the concrete override is resolved at runtime through the object's vtable pointer. |
Definition at line 49 of file C++ Implimentation.cpp.
| void makeSpeak | ( | ISpeaker & | s | ) |
Contractual Dispatch via Dynamic vtable Lookups.
| s | Reference to the ISpeaker interface contract. |
Definition at line 140 of file C++ Implimentation.cpp.