A link is a connection between specific objects — physical or conceptual. "Priya works for Nimbus Corp" describes a link between one Person object and one Company object. An association describes groups of link
An association is drawn as a line between two class boxes, labeled with an italic name. This diagram says: some number of Person objects can be linked, through WorksFor, to some number of Company objects. The actual links — which specific people work for which specific companies — only show up in an object diagram.
Multiplicity states how many objects on one end of an association can be linked to a single object on the other end. It's written as a number or a range at each end of the association line — the most common shorthand, an asterisk, simply means "zero or more."
Multiplicity is not the same as cardinality. Multiplicity is the rule — the constraint written on the diagram. Cardinality is the actual count in a particular case at a particular moment.
Just as an association itself can have a name, each end of an association can too. An association end name describes the role a class plays from the other side's point of view — usually a noun, not a verb.
Here, a Person plays the role of employee with respect to a company, and a Company plays the role of employer with respect to a person. These end names matter most in two situations that come up constantly in student projects:
Directory that can contain other Directory objects — there's no second class name to lean on for clarity, so end names like container and contents become the only way to tell the two roles apart.User and Directory are connected by both an "owns" relationship and an "is authorized to use" relationship, end names (or association names) are what keep the two links from being confused with each other.By default, the objects on a "many" end of an association have no inherent order — think of them as an unordered set. Sometimes, though, order genuinely matters to the problem. A stack of overlapping windows on a screen, for example, needs to remember which window is on top.
Writing {ordered} next to an association end tells the reader — and eventually, whoever implements the model — that sequence is a meaningful part of this relationship
Normally, an association allows at most one link between any given pair of objects. To allow the same pair of objects to be linked more than once, mark the association end with {bag} or {sequence}.
An unordered collection that allows duplicates. Multiple links between the same pair of objects are permitted, but no particular order among them is implied.
An ordered collection that allows duplicates — effectively {ordered} plus repetition allowed. A flight itinerary that revisits the same airport twice needs a sequence, not just an ordered set.
| Annotation | Ordered? | Duplicates allowed? |
|---|---|---|
| (none) | No | No |
{ordered} | Yes | No |
{bag} | No | Yes |
{sequence} | Yes | Yes |
Sometimes a piece of data doesn't belong to either object in a relationship — it belongs to the link itself. An association class lets an association carry its own attributes and operations, drawn as a class box attached to the association line by a dashed line.
A qualified association uses an extra attribute . that describes the association. It is the Attributr which is used toconnect two objects
Without a qualifier, a bank services "many" accounts, and finding one specific account means searching the whole set. With accountNumber as a qualifier, the model states directly: given a bank and an account number, there's at most one matching account