Showing Static Relationships in a Class Diagram


Showing Static Relationships in a Class Diagram

There is a lot more to this world than just objects. Relationships between objects are just as important as the objects. In UML these relationships are defined using associations and links. To give you a concrete sense of these relationships, we use several different examples. Our first example involves a company that rents crash dummies to clients for tests. Consider this the Rent-A-Crash Dummy example. You have to relate the crash dummies to the clients who rent them—and show that a specific crash dummy named MAX was rented to a client named Safety ’R Us.

Remember An instance of a class is an object. We use the words object and instance interchangeably.

Links are instances of associations. Associations relate classes, whereas links relate instances of those classes (objects). So a link would connect an object in the Client class with an object in the CrashDummy class.

You show a simple association by drawing a line between the two classes you want to relate. Likewise, you show a link by drawing a line between two instances of two associated classes.

After you have specified that two classes are associated, think about a few details for depicting the association. Here’s a quick list (which we discuss further later in this chapter):

  • Name: Normally an association has a name—placed along the association line—that describes the relationship between the classes. Older versions of UML specified italics for the association name so it would stand out. UML 2 doesn’t require italicized association names—but it’s not a bad idea. A good practical rule is to use the form that your UML modeling tool uses.

    Names of associations are not underlined, but the names of links are. Use associations to connect classes; use links to connect objects.

  • Multiplicity: Use multiplicity to specify how many instances of one class can be linked to a single instance of another class. The multiplicity is shown as a number (or numbers) indicating the lower and upper bounds on the number of links at each end of an association.

  • Roles: Here you name the class on one end of an association by indicating how the class participates in that association. The name is placed at the end of the association closest to the participant class it is identifying.

  • Constraints: Employ constraints on an association if its underlying links must follow some rule(s). Place a constraint in curly brackets { } close to the association.

  • Qualifiers: Use qualifiers to show that navigation from an instance of one class to a partitioned set of instance(s) of another class must be based on an attribute of that other class. Place a qualifier in a box appended to the class from which the navigation begins.

  • Directional navigation: Utilize a navigation arrow on the association line when one class can communicate one way with another. Show directional navigation with an arrowhead at one end of the association, indicating the direction of allowable communication.

Well, yes, there are a lot of details here, but the chapter takes you through them. Fortunately, you don’t have to place all these details on each and every association in your diagrams. Usually the name of the association and the multiplicities are all you need.




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