Professional Documents
Culture Documents
public public +
protected protected #
package ~
private private -
Relationships Between Classes
• Association OR
– Permanent, structural, “has a”
– Solid line (arrowhead optional)
• Aggregation
– Permanent, structural, a whole created from parts
– Solid line with hollow diamond from whole
• Composition
– Whole part relationship (solely owns the part)
– Solid line with solid diamond from whole
• Dependency
– Temporary, “uses a”
– Dotted line with arrowhead
• Generalization
– Inheritance, “is a”
– Solid line with open (triangular) arrowhead
• Implementation
– Dotted line with open (triangular) arrowhead
Class Relationships
Relation
Aggregation
Composition
Association
V. Ramesh
691205-5678
People Tax_files
1 1
People Associated with Tax_files
Multiple Association – example
Bhim
motherOf
Kunti Yudhistir
Arjun
Women People
1 *
Women Mother of People
UML Syntax: Association
role B
Class A Class B
role A
• A Person works for a Company.
Role
employee employer
Person works for
Company
Association Name
Member 1 borrowed 0..5
Book
eats
Lion * * Animal
Example 1: Association
• A teacher teaches 1 to 3 courses (subjects)
• Each course is taught by only one teacher.
• A student can take between 1 to 5 courses.
• A course can have 10 to 300 students.
1
teaches 1..3
Teacher Course
1..5
takes
Students
10..300
Example 2: Association
• A Student can take up to five Courses.
• A student has to enroll in at least one course.
• Up to 300 students can enroll in a course.
• A class should have at least 10 students.
Student credits hasEnrolmentOf
1..5
Course
10..300 Enrols in
credits hasEnrolmentOf
Student Course
10..300 Enrols in 1..5
Person Friend of
Connects to
*
Computer
*
next
LinkedListNode
previous
Implementation of Association
• Java Implementation 1 Borrowed 1
Member Book
by
– Use a reference variable
of one class as an
attribute of another class bookName: OOSD
aBook author: Gamaa
• Member Class ISBN: 12234434
Book Reference
public class Member{
Book instance
private Book book;
public issueBook(Book aBook){
setBook(aBook); bookName:
memberName: AKK
abook.setLender(this);} memberNumber: 412323
setBook(Book aBook){
book=aBook; }
…}//end class
Implementation contd.
• Java Implementation 1 Borrowed 1
Member Book
by
– Use a reference variable
of one class as an
attribute of another class bookName: OOSD
abook author: Gamaa
• Book Class Book Reference ISBN: 12234434
public class Book{ Book instance
private Member member;
setLender(Member aLender){
bookName:
member=aLender; memberName: AKK
} memberNumber: 412323
…
}//end class
Implementation Example 2
has Account
• Java Code Customer
1 1..*
class Customer{
private ArrayList <Account> accounts =
new ArrayList<Account>();
public Customer(){
Account defaultAccount = new
Account();
accounts.add(defaultAccount);
}
}
Ternary Association
1 1
• Decompose it to a set of Man Woman
binary associations
1..3
Priest
1 1 1 1
Man Marriage Woman
Participates Participates
* in
in
Performed by
1..3
Priest
Aggregation
Library
• A special kind of association
• Models whole-part relationship
between things
Books
• Whole is usually referred to as
composite
• the child can exist independently of the
parent.
• Composition
– child cannot exist independent of the
parent
Hand Finger
1 0..7
Aggregation Implementation
A «B»
A implements interface B
UML Example – I
• Read the UML Diagrams