Parallel hierarchies problem

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: The parallel hierarchies problem is when you run into this situation in your design: Image:Deferred state variables 1.jpg You need to have a Vehicle hierarchy for different vehicles...)
 
m
Line 4: Line 4:
 
[[Image:Deferred state variables 1.jpg]]
 
[[Image:Deferred state variables 1.jpg]]
  
You need to have a Vehicle hierarchy for different vehicles, and an Operator hierarchy for different Operators of Vehicles. In this case the operator is stored in the abstract Vehicle class. This means that it is possible that a Plane class could be given a Driver operator, which is obviously invalid.
+
You need to have a Vehicle hierarchy for different vehicles, and an Operator hierarchy for different Operators of Vehicles. In this case the Operator is stored in the abstract Vehicle class. This means that it is possible that a Plane class could be given a Driver operator, which is obviously invalid.
  
 
This problem cannot be completely avoided, but you can structure it in the best possible way by using the [[Intelligent children pattern]] and the [[Defer identification of state variables pattern]] (which are closely related).
 
This problem cannot be completely avoided, but you can structure it in the best possible way by using the [[Intelligent children pattern]] and the [[Defer identification of state variables pattern]] (which are closely related).

Revision as of 03:48, 22 August 2008

The parallel hierarchies problem is when you run into this situation in your design:


Deferred state variables 1.jpg

You need to have a Vehicle hierarchy for different vehicles, and an Operator hierarchy for different Operators of Vehicles. In this case the Operator is stored in the abstract Vehicle class. This means that it is possible that a Plane class could be given a Driver operator, which is obviously invalid.

This problem cannot be completely avoided, but you can structure it in the best possible way by using the Intelligent children pattern and the Defer identification of state variables pattern (which are closely related).

TODO: example of better structure after applying pattern.

See also

Personal tools