Home > Articles > Software Development & Management > UML

This chapter is from the book 16.4 Ways to Show UML Attributes: Attribute Text and Association Lines

16.4 Ways to Show UML Attributes: Attribute Text and Association Lines

Attributes of a classifier (also called structural properties in the UML[1]) are shown several ways:

  • attribute text notation, such as currentSale : Sale.
  • association line notation
  • both together

Figure 16.3 shows these notations being used to indicate that a Register object has an attribute (a reference to) one Sale object.

Figure 16.3 Attribute text versus association line notation for a UML attribute.

The full format of the attribute text notation is:

visibility name : type multiplicity = default {property-string}

Also, the UML allows any other programming language syntax to be used for the attribute declaration, as long as the reader or tool are notified.

As indicated in Figure 16.1, visibility marks include + (public), - (private), and so forth.

Guideline: Attributes are usually assumed private if no visibility is given.

Notice in Figure 16.3 that this attribute-as-association line has the following style:

  • a navigability arrow pointing from the source (Register) to target (Sale) object, indicating a Register object has an attribute of one Sale
  • a multiplicity at the target end, but not the source end
    • use the multiplicity notation
  • a rolename (currentSale) only at the target end to show the attribute name
  • no association name

Guideline: When showing attributes-as-associations, follow this style in DCDs, which is suggested by the UML specification. It is true that the UML metamodel also allows multiplicity and rolenames at the source end (e.g., the Register end in Figure 16.3), and also an association name, but they are not usually useful in the context of a DCD.

Guideline: On the other hand, when using class diagrams for a domain model do show association names but avoid navigation arrows, as a domain model is not a software perspective. See Figure 16.4.

Figure 16.4 Idioms in association notation usage in different perspectives.

Note that this is not a new kind of association notation. It’s the same UML notation for associations explored while applying class diagrams to domain modeling. This is an elaboration of the notation for use in the context of a software perspective DCD.

Guideline: When to Use Attribute Text versus Association Lines for Attributes?

This question was first explored in the context of domain modeling. To review, a data type refers to objects for which unique identity is not important. Common data types are primitive-oriented types such as:

  • Boolean, Date (or DateTime), Number, Character, String (Text), Time, Address, Color, Geometrics (Point, Rectangle), Phone Number, Social Security Number, Universal Product Code (UPC), SKU, ZIP or postal codes, enumerated types

Guideline: Use the attribute text notation for data type objects and the association line notation for others. Both are semantically equal, but showing an association line to another class box in the diagram (as in Figure 16.3) gives visual emphasis—it catches the eye, emphasizing the connection between the class of objects on the diagram. See Figure 16.5 for contrasting examples.

Figure 16.5 Applying the guidelines to show attributes in two notations.

Again, these different styles exist only in the UML surface notation; in code, they boil down to the same thing—the Register class of Figure 16.5 has three attributes. For example, in Java:

public class Register
private int id;
private Sale currentSale;
private Store location;
// …

The UML Notation for an Association End

As discussed, the end of an association can have a navigability arrow. It can also include an optional rolename (officially, an association end name) to indicate the attribute name. And of course, the association end may also show a multiplicity value such as ‘*’ or ‘0..1’. Notice in Figure 16.3 that the rolename currentSale is used to indicate the attribute name.

And as shown in Figure 16.6, a property string such as {ordered} or {ordered, List} is possible. {ordered} is a UML-defined keyword that implies the elements of the collection are (the suspense builds…) ordered. Another related keyword is {unique}, implying a set of unique elements.

The keyword {List} illustrates that the UML also supports user-defined keywords. I define {List} to mean the collection attribute lineItems will be implemented with an object implementing the List interface.

How to Show Collection Attributes with Attribute Text and Association Lines?

Suppose that a Sale software object holds a List (an interface for a kind of collection) of many SalesLineItem objects. For example, in Java:

public class Sale
private List<SalesLineItem> lineItems = 
			new ArrayList<SalesLineItem>();
// …

Figure 16.6 shows two ways to illustrate a collection attribute in class diagrams.

Figure 16.6 Two ways to show a collection attribute in the UML.

Notice also the optional use of property strings such as {ordered}.

  • + Share This
  • 🔖 Save To Your Account