- Specialization (Subtyping - Ideal) - Ideal form of inheritance
Florist is a specialization of Shopkeeper
- Specification - (Ideal) - Special case of specialization
Used to guarantee that the subclasses all maintain the same interface.
Often the parent class only specifies methods that must be defined in
the child class. Parent is often an abstract class. Substitutability
is maintained.
Shape is the abstract parent class specifying that all child
classes have certain properties and functionalities.
- Construction (Not great) - Used when one class provides most of the
functionality needed by another but the 2 classes may not have any
relationship. Substitutability may not be maintained. C++ has a
mechanism (private inheritance) that makes this type of subclassing
less dangerous to use.
Dictionary and symbol table from the book
- Generalization - (Bad) - Opposite of specialization - Child extends
the behavior of the parent class to be more general. Avoid whenever
possible. At least one method is overriden.
Shopkeeper as child of Florist
- Extension - (OK) - maintains substitutability - adds totally new
abilities.
StringSet is a Set - new methods for handling stuff for strings
- Limitation - (Bad) - the behavior of the subclass is smaller or
more restrictive than that of the parent. Does NOT maintain
substitutability. Avoid as much as possible
Making Stack from the double-ended-queue data structure
- Variance - (Weak) - Two or more classes have similar implementations
but don't have an hierarchical relationship. Avoid - it would be
better to abstract out the commonalities into a parent class for both.
Mouse and Tablet - same but different - better to use PointingDevice
as a parent for both mouse and tablet
- Combination - (OK) - Combination of features from 2 or more classes -
multiple inheritance - very complex to use - most languages don't
support it.
iostream inherits from both istream and ostream