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 MachinesFigure 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 Lifecycle13.3.2 Subclass State MachinesSome 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
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. |