ConstructiCat Logo
CodeBust.
Browse section ▾

Parallel Inheritance Hierarchies.

Whenever you create a subclass for a class, you find yourself needing to create a subclass for another class.

##Signs and Symptoms

Whenever you create a subclass for a class, you find yourself needing to create a subclass for another class.

abstract class Engine {}
class CarEngine extends Engine {}
class TruckEngine extends Engine {}

abstract class EngineView {}
class CarEngineView extends EngineView {}
class TruckEngineView extends EngineView {}
// adding BusEngine also forces you to add BusEngineView

##Reasons for the Problem

All was well as long as the hierarchy stayed small. But with new classes being added, making changes has become harder and harder.

##Treatment

##Payoff

  • Reduces code duplication.

  • Can improve organization of code.