13.3 Dynamics in Generalization Hierarchies


Classes arranged in a generalization hierarchy may also have lifecycles formalized using state machines. Depending on the behavioral differences between the subclasses, we may choose to model separate lifecycles for each subclass or a single lifecycle for the superclass.

13.3.1 Superclass State Machines

Figure 6.13 on page 97 showed how the Product is divided into subclasses for Books, Recordings, and Software. This distinction, however, does not make a difference to the basic lifecycle of a Product. All products are proposed, approved for sale, finally discontinued from sale, and possibly reinstated. Since this basic lifecycle applies to all types of Product, we formalize a single superclass state machine, as shown in Figure 13.10.

Figure 13.10. Product Superclass Lifecycle

graphics/13fig10.gif

13.3.2 Subclass State Machines

Some specializations are created because the different subclasses exhibit different behavior. The bookstore has two different kinds of clerks: shipping clerks who pack and ship customer orders and stock clerks who receive product and stock the warehouse. Different subclasses, as shown in Figure 13.11, are a useful way of modeling these distinct roles.

Figure 13.11. Warehouse Clerk Subclasses

graphics/13fig11.gif

Multiple Lifecycles and Multiple Hierarchies

It is possible to create a state machine for a superclass and state machines for corresponding subclasses. Similarly, when a class is subclassed into multiple hierarchies, we can create separate state machines for each of these subclasses.

Since all these superclass and subclasses are just classes, they can each have their own state machines, but we have found that in most cases, only one set of state machines is needed.

In other words, don't build multiple statechart diagrams even though you can.

When subclasses are created because the behaviors of the subclasses are different, create separate state machines for each subclass. The state machine of a stock clerk involves activities associated with restocking the warehouse as product arrives from the publishers, while the quite different activities of the shipping clerk were illustrated in the state machine in Figure 12.12 on page 210.



Executable UML. A Foundation for Model-Driven Architecture
Executable UML: A Foundation for Model-Driven Architecture
ISBN: 0201748045
EAN: 2147483647
Year: 2001
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net