6.6 Reflexive Associations


Links can exist between instances of the same class, for example, between nodes in a ring network or authors of a book. Associations that have the same class at both ends are known as reflexive associations.

Definition: A reflexive association is an association between instances of the same class.

Reflexive associations to model sequence.

The individual author credits on a book (Authorships) appear in a certain sequence. Each credit may have a role (e.g., editor, compiled by, as told to). We can model this as in Figure 6.19.

Figure 6.19. Reflexive Association Modeling Sequence

graphics/06fig19.gif

Generally these reflexive associations are conditional at both ends: There is a first Authorship that has no predecessor and a last Authorship that has no successor.

In cases where a sequence is a closed loop, the association can be unconditional, as in Figure 6.20.

Figure 6.20. Closed Loop Reflexive Association

graphics/06fig20.gif

In the network, the nodes form a complete circle in which each node has one other node to the left and one to the right. All instances are equal and participate equally in the IS NEXT TO association.

Using reflexive associations to model hierarchies.

Some reflexive associations model hierarchy. Consider a scheme for categorizing products, as shown in Figure 6.21.

Figure 6.21. A Category Hierarchy

graphics/06fig21.gif

Some product categories are not part of any parent category (the root). For example, Product is part of no other category but is divided into Computers, Movies, and other categories. Others are not divided into any child categories. For example, C++ is part of Programming Languages and C++ is divided into nothing (a leaf).

Categories are part of at most one parent category and can be divided into zero or more child categories, hence the association, R14, is one-to-many and biconditional.

As modeled in Figure 6.22, any Product can be associated with any Product Category. If, however, we want to associate Products only with leaf categories, we will need to model it differently, as in Figure 6.23.

Figure 6.22. Reflexive Association Modeling the Category Hierarchy

graphics/06fig22.gif

Figure 6.23. Subtyping ProductCategory

graphics/06fig23.gif

Here, we've divided the categories into "nonleaf" categories, which must be divided into other categories, and "leaf" categories, which are not divided. In this way, only those categories that are not subdivided into other categories can be used to categorize products.

What started out as a simple reflexive association is now modeled with separate classes for each role. This approach, while requiring more classes, is likely to be more useful and correct as the root, nonleaf, and leaf categories are each likely to have distinct attributes and behaviors that would be too difficult to capture in a single Category class.



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