Parallel hierarchies problem
(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 (Reverted edits by Ebybymic (Talk); changed back to last version by Yugan Yugaraja) |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | + | [[Image:Deferred state variables 1.jpg|frame|Fig.1 Parallel hierarchies problem]] | |
+ | The parallel hierarchies problem is when you have two parallel inheritance hierarchies associated by composition. ''Fig.1''. The problem exists only if there are restriction on the interaction of the objects as in the example below. | ||
− | |||
− | You need to have a Vehicle hierarchy for different vehicles, and an Operator hierarchy for different Operators of Vehicles. In this case the | + | 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. If there are restrictions on which operators can use which vehicles then 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). | ||
− | + | A solution to the Vehicle-Operator parallel hierarchies problem example can be found at [[Intelligent children pattern]]. | |
== See also == | == See also == | ||
Line 14: | Line 14: | ||
* [[Defer identification of state variables pattern]] | * [[Defer identification of state variables pattern]] | ||
* [[Intelligent children pattern]] | * [[Intelligent children pattern]] | ||
+ | * [[State machine design]] | ||
+ | * [[Double Dispatch]] |
Latest revision as of 03:21, 25 November 2010
The parallel hierarchies problem is when you have two parallel inheritance hierarchies associated by composition. Fig.1. The problem exists only if there are restriction on the interaction of the objects as in the example below.
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. If there are restrictions on which operators can use which vehicles then 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).
A solution to the Vehicle-Operator parallel hierarchies problem example can be found at Intelligent children pattern.