Link and Association
A link is a physical or conceptual connection among objects.
Most link relate two objects but some links relate three or more objects.
e.g. Smith works for simplex company.
A link is an instant of an association.
An Association is a description of a group of links with common structure and common
semantics.
UML 1
Link and Association continue…
An association connects related classes and it is also denoted by a line. (with
multiple line segments)
It is good to arrange the classes in an association from left to right ,if
possible.
The associations and links often appears as verbs in problem statements.
UML 2
Link and Association continue…
Person WorksFor Company Class
For example, a person * *
diagram
name name
John:Person
name=“john”
GE:Company
Mary:Person Name=“GE”
name=“Mary”
Sue:Person IBM:Company Object
Name=“Sue” Name=“IBM” diagram
Jeff:Person
Name=“jeff”
UML 3
Multiplicity
Multiplicity specifies the number of instances of one class that may relate
to a single instance of an associated class.
UML diagrams explicitly list multiplicity at the end of the association lines.
Multiplicity Indicators
Exactly one 1
Zero or more (unlimited) * (0..*)
One or more 1..*
Zero or one (both inclusive) 0..1
Specified range 2..4
Multiple, disjoint ranges 2, 4..6, 8
UML 4
Multiplicity Continue…
HasCapital Class
Country CapitalCity diagram
1 1 name
name
HasCapital Ottawa:CapitalCity
Canada:Country
Name=“Canada” Name=“Ottawa”
HasCapital Paris:CapitalCity
France:Country
Name=“France” Name=“Paris”
Object
diagram
UML 5
Association End Names
If we consider one to many association then it has two ends-an end
with a multiplicity of “one” and an end with a multiplicity of “many”.
We can also give the name to both the ends.
Association end names often appear as nouns in problem descriptions.
Example
employee WorksFor employer Company
Person
* 0..1
UML 6
Association Classes
The abstract class is a class that allows the association to be a class itself.
When two classes are related with each other by an association link, then the association
itself can have attributes and operations
Hence, association can be represented by a class.
The UML notation for an association class is a box attached to the association by a dashed
line.
/etc/abc.txt read John
* *
File User
AccessibleBy
UML 28
accessPermission
Qualified Associations
A qualified association is an association in which an attribute called the
qualifier disambiguates the objects for a “many” association end.
possible to define for one-to-many and many-to-many asso.
A qualifier selects among the target objects, reducing multiplicity from
“many” to “one”.
Example:- A bank services multiple accounts.
UML 8
Qualified Associations Continue…
Bank Bank
a/cNo. 1
1
Qualifier
0..1 *
Account Account
a/cNo.
Qualified
Not qualified
UML 9
Generalization and Inheritance
Generalization is the relationship between a class (super class)
and one or more variations of the class (subclasses).
Super Class (Base class) Super Class
Provides common functionality and data members
Subclass (Derived class)
…
Inherits public and protected members from the super class
Can extend or change behavior of super class by overriding
methods Subclass
Overriding
UML 31
Subclass may override the behavior of its super class
Generalization and Inheritance Continue…
A large hollow arrowhead denotes generalization.
UML 11
Generalization – advantages
Polymorphism
Find common characteristics among classes
Define hierarchies
Reuse of the code
UML 12
A sample class diagram: Attendance Management System
UML 13