Parallel Inheritance Hierarchies
Symptoms
You make a new subclass in one hierarchy, and find yourself required to create a related subclass in another hierarchy. You find two hierarchies where the subclasses have the same prefix. (The naming reflects the requirement to coordinate hierarchies.)
This is a special case of Shotgun Surgery, discussed earlier.
Causes
The hierarchies probably grew in parallel, a class and its pair being needed at the same time. As usual, it probably wasn't bad at first, but after two or more pairs get introduced, it becomes too complicated to change one thing. (Often both classes embody different aspects of the same decision.)
What to Do
Payoff
Reduces duplication. May improve communication. May reduce size.
Contraindications
None identified. (This smell may happen along the way from improving a particularly tangled situation.)
| Exercise 42 Duplicate Observed Data. |
Duplicate Observed Data splits a class in two—one part model, the other part view. (For example, it might turn Card into CardModel and CardView.) It is often natural for the model classes to form a hierarchy (they have similar notification needs), and it's natural for the views to form a hierarchy (they all display). This sounds like a Parallel Inheritance Hierarchy. Is it a problem?
See Appendix A for solutions.
|
|