Considering discriminators and alternate designs
A discriminator is an object-oriented concept that helps outline the reasons why a given class is derived from its base class. Discriminators tend to characterize the types of groupings of specializations that exist for a given base class.
For example, in the aforementioned program examples with diamond-shaped hierarchies, we have the following discriminators (shown in parentheses), outlining our purpose for specializing a new class from a given base class:
Figure 9.1 – Multiple inheritance diamond-shaped design shown with discriminators
Whenever temptation leads to the creation of a diamond-shaped hierarchy, examining the discriminators can help us decide whether the design is reasonable, or whether perhaps an alternate design would prove better. Here are some good design metrics to consider:
- If the discriminators for the sibling classes that are being brought back together are the same, then...