Back to Catalog
Code Smells
Change Preventers
Parallel Inheritance Hierarchies
Two or more class hierarchies that grow in parallel.
Intent & Description
'
π― Intent
Identify when you have to make changes to multiple inheritance hierarchies simultaneously.
π Context
Creating a subclass in one hierarchy requires creating a corresponding subclass in another hierarchy.
π‘ Solution
Merge the hierarchies or eliminate the dependency between them using composition.'
Real-world Use Case
Use when adding a class to one hierarchy requires changes to another.
Source
π TL;DR
Parallel hierarchies create unnecessary coupling. Merge them or use composition to break the dependency.