To understand which cardinality to put where, use the following technique:
- Replace association name, with endpoint role names. Multiplicity is expressed with respect to the role.
- Remember that the multiplicity is expressed as association participation on a "per object" basis, not on the relationship as a whole.
- Read the association between class X and Y using the pattern "An object of class X has as "x's-role" "y's-multiplicity" objects
of class Y.
See the example, left, with labeled names of associations employees and head between classes Employee and Department. Consider that a department has one head, and many possible employees, and that an Employee is part of zero or more departments, but may be the head of zero or one of these. It is not obvious on which association endpoint to put each multiplicity notation.This will result in a new diagram, whether diagrammed or in our head. This diagram shows the
roles each class has in each association.To follow the above process, we must first replace named association with named roles. This will The "employees" association name has been replaced with role names of "partOf" and "employs". The "head" association name has been replaced with role names "headOf" and "headedBy". With roles named, its time to place multiplicity indicators on our associations.First, for the top employs/partOf roles we state that an employee is part of one department,
Cross-checking this diagram against our above rule, we see the diagram is stating the following:
An object of class Employee is part of 1 Department.Using this system, you should be able to read multiplicity on class diagrams, and effectively adorn your class diagrams with multiplicity indicators.
An object of class Department employs 1 or more Employees.
An object of class Employee is optionally head of 1 Department.
An object of class Department is headed by exactly 1 Employee.
Want to learn UML? Consider taking our UML Course.
4 comments:
I was trying to refresh my UML memories from school, and your post was useful. Thanks!
Great! If you are located in St. Louis, consider taking our UML course (link in post).
Good dispatch and this enter helped me alot in my college assignement. Thank you on your information.
Nice post and this enter helped me alot in my college assignement. Say thank you you as your information.
Post a Comment