Code quality and technical debt

Parallel inheritance hierarchies

Also known as Parallel inheritance hierarchies, Parallel inheritance hierarchies in software engineering

By WeavePublished 1 min read

Definition

A code smell in which adding one subtype in one hierarchy requires adding a matching subtype in another.

What it means

Parallel inheritance hierarchies occur when two class families evolve in lockstep because their responsibilities are coupled through inheritance. The pattern can increase change cost and make the relationship hard to discover. Composition or a shared policy object may reduce the need for synchronized subclasses.

Example

Adding a new report format requires both a renderer subclass and a matching exporter subclass. The team examines whether a renderer contract can be passed into one exporter instead.

Limitations

Parallel structures can be intentional when they represent separate dimensions and provide useful type safety. Flattening them may create conditionals or lose clarity. Evaluate the actual variation axes and ownership.

How to use the signal

Confirm that the hierarchies represent separate dimensions before replacing them with composition or a more explicit policy object.

Weave can help relate synchronized hierarchy changes to review iteration and rework. Use static structure and history to identify the pattern, then use Weave for prioritization.

How this relates to Weave

Weave can help relate synchronized hierarchy changes to review iteration and rework. Use static structure and history to identify the pattern, then use Weave for prioritization.

Explore Engineering intelligence

Sources and further reading

  1. Martin Fowler, Refactoring and software design