Cycling Around Class Diagrams


Modelers are not always careful with the multiplicity they show on class diagrams. However, you can discover multiplicity inconsistencies easily if there are cycles in the class diagram. You have a cycle if you find a path that starts at a class, goes along a series of associations and connected classes, and comes back to your starting class. Figure 21-4 illustrates a cycle from Person to Policy to Vehicle back to Person.


Figure 21-4: Class diagram with incorrect multiplicities.

To check for inconsistencies of multiplicity, work through the following steps:

  1. Select one of the classes in the cycle as the starting point.

    In the example in Figure 21-4, start at Person.

  2. Follow the association from the starting class to the next class in the chain.

    This takes you to Policy because Person connects to Policy through the holds association.

  3. Take a look at the multiplicity at the end of the association you just followed next to the class you found in Step 2.

  4. Make a mental note of what that multiplicity means for the two classes.

    A person can hold exactly one policy.

  5. Now go back to the starting class and follow the chain of classes in the opposite direction until you get to the class you found in Step 2.

    In the running example using Figure 21-4, you have Person to Vehicle to Policy.

  6. Take a look at the multiplicity at the end of the last association you just followed to get to the class you found in Step 2.

    In this example, this multiplicity is also exactly 1.

  7. Consider the meaning of the indirect relationship between the starting class and the ending class via this other route.

    A person can drive zero or more vehicles and each vehicle can only be insured by one policy.

  8. Check to see whether the meaning you got from the diagram in Step 4 squares with the meaning you got in Step 7.

    If it doesn’t, then you have a potential inconsistency in multiplicity—and it must be fixed. If you are to believe the diagram in Figure 21-4, an instance of the Person class can only hold one policy, and a policy insures one vehicle. But that same person can drive more than one vehicle (where each vehicle is insured by exactly one policy).

    Those two statements are inconsistent under most circumstances. How can a person hold only one policy (if you follow the holds association) and hold more than one policy if he or she drives several vehicles and each of those vehicles can have a different policy?

 Tip   Check all the cycles in your class diagrams for contradictions by using the eight steps given here.




UML 2 for Dummies
UML 2 For Dummies
ISBN: 0764526146
EAN: 2147483647
Year: 2006
Pages: 193

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