Complex constraints involve multiple objects and their links, and capture more complex rules than are shown in the previous section on simple constraints. Multiplicity constraints are a special case of complex constraints in that they have their own notation; you do not need to capture multiplicity constraints using the OCL.
Multiplicity notation is used in Figure 10-1s class diagram to define multiplicity rules that must be respected. One such constraint states that a project relates to a single organization and to a single team. Figure 10-3 shows an object diagram that is invalid because it violates those rules.
Figure 10-3. Invalid relationships between organizations, a project, and teams
The UML’s multiplicity notation captures rules regarding the number of objects that may be related to one another. However, using the OCL, many other complex rules may be expressed using constraints.
You could capture multiplicity constraints using the OCL, but instead you should use the notation for such constraints already built into the UML.
Figure 10-1 shows the details about organizations, projects, teams, and people, but does not indicate whether a project and its team must relate to the same organization, nor does it indicate whether a team and its members must relate to the same organization. Using the OCL, it’s possible to create a complex constraint that enforces ...