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.
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, while a department employs one or more employees. We place a 1 on the employs role, and a 1..* on the partOf role. For the headedBy/headOf roles we state that an employee optionally the head of one department, while a department is headed by exactly one employee. This results in our final diagram.
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