O'Reilly logo

Learning UML by Sinan Si Alhir

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple Constraints

Simple constraints that involve one object, or two objects and their link, provide the foundation for working with more complex constraints that involve multiple objects and their links.

Attributes

To specify a rule about the values of an object’s attributes, you can refer to an object’s attribute from the object itself by using the name of the attribute.

Within the context of an organization, the following expression indicates that the name of an organization may not be an empty string:

Name <> ''

Using the keyword self, this rule may be described as follows:

self.Name <> ''

Notice that a literal string is enclosed in single quotes.

Figure 10-2 updates Figure 10-1 to show how the rule is captured. Look specifically at the top compartment for Organization.

Organizations with an OCL expression indicating that organizations must have names

Figure 10-2. Organizations with an OCL expression indicating that organizations must have names

Within the context of a person, the following expression indicates that a person must work more than 10 hours and less than or equal to 40 hours:

HoursAvailable > 10 and HoursAvailable <= 40

Using the keyword self, this rule may be described as follows:

self.HoursAvailable > 10 and self.HoursAvailable <= 40

Notice that the keyword self is used at the beginning of each occurrence of the HoursAvailable attribute. Also notice that I can access this attribute even though it is private, because the expression is written within the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required