13.1 Dynamically Simple Associations


Links between objects are created and deleted over time. There are several approaches to modeling associations. We can

  • Create the objects and the link synchronously, and not build any statechart diagrams for the classes or the links.

  • Build a statechart diagram for one class or the other, endowing that class with the responsibility of managing creation and deletion of the objects and the link.

  • Build a statechart diagram for both classes, assigning the responsibilities for creating and deleting the link between the classes.

  • Abstract the association as an association class and use the association class to house the statechart diagram.

13.1.1 Associations without Explicit Lifecycles

Some associations simply exist. In the online bookstore, new products are made available for sale and some products are discontinued. Each product is published by some Publisher. That means that whenever a new product is added, there must be a publisher for that product, as shown in Figure 13.1.

Figure 13.1. Class Diagram for Publisher and Product

graphics/13fig01.gif

The association multiplicity specifies the rules for what must happen when instances of the classes are created and deleted. For example, whenever a product is created or deleted, a link for the Publisher PRODUCES AND MARKETS Product association must be correspondingly created or deleted. If a Publisher is deleted, all the products published by that publisher must be deleted as well.

13.1.2 Dynamic Associations with Association Classes

Other associations progress through distinct stages during which different rules and policies apply. These associations are modeled using an association class with a state machine.

The state machine prescribes the behavior of a typical unspecified link. Each link executes this same state machine, and, just as with a class, we use the term state machine instance to refer to the execution of the state machine by a particular instance of the association.

The Product Selection association class in the online bookstore, shown in Figure 13.2, has a statechart diagram that receives signals to add a new selection, to change the quantity of an existing selection, and to remove the selection from the shopping cart.

Figure 13.2. Class Diagram for Product Selection

graphics/13fig02.gif

The statechart diagram for the Product Selection is shown in Figure 13.3.

Figure 13.3. Statechart Diagram for Product Selection

graphics/13fig03.gif

Since a Shopping Cart must have at least one Product (multiplicity 1..*), when a Product Selection is deleted it checks to see if its deletion would result in an empty cart; if the selection being deleted is the last one in the cart, it signals the cart to delete itself, thereby maintaining the integrity of the association. The coordination between the classes and the online customer external entity is shown in the collaboration diagram in Figure 13.4.

Figure 13.4. Collaboration between Product Selection and Order

graphics/13fig04.gif



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