Structural Design ◾ 171
unsigned getRange() {return getMax()
– getMin();}
};
class maxRangeCompose2
{ …
minMax m;
public:
unsigned getRange(){return m.getMax() – m.getMin();}
};
Choosing inheritance rather than composition, or vice versa, yields
little dierence in this example. Code is reused either way. ere is no
variability in the relationship between the minMax component and the
minMaxMean type (or the maxRange type). Each design denes an object
with exactly one embedded minMax component. e relationship between
parent and child (or object and subobject) is xed, in terms of lifetime
association, unit cardinality, and ownership. Moreover, substitutability is
not imperative. at is, there appears to be no client need fo