Вы находитесь на странице: 1из 5

Association - Multiplicity

A Student can take many Courses and many Students


can be enrolled in one Course.
UML and Classes, Objects
Student Course
and Relationships [ 2] * takes *

Defining Domain Models Using 254: Course


Alice: Student
Class Diagrams

Jill: Student 253: Course

1 2

Notes Notes


One class can be relate to another in a 

Multiplicity can be expressed as,




One-to-one 

Exactly one - 1


One-to-many 

Zero or one - 0..1




One-to-one or more 

Many - 0..* or *


One-to-zero or one 

One or more - 1..*




One-to-a bounded interval (one-to-two 

Exact Number - e.g. 3..4 or 6


through twenty) 

Or a complex relationship – e.g. 0..1, 3..4,




One-to-exactly n 6..* would mean any number of objects




One-to-a set of choices (one-to-five or eight) other than 2 or 5

3 4

Association - Self Association - Self




An association that connects a class to A Company has Employees.


itself is called a self association. A single manager is responsible for up to 10 workers.

1
Employee
manager
Responsible worker
for 0..10

5 6
Association - Multiplicity Class Relationships

A cricket team has 11 players. One of them is the


captain.


Association
A player can play only for one Team. 

Generalization
The captain leads the team members.


Realization
Team
Member
Captain

1


Dependency
0..1
Player Team
10

11 member of 1
Captain
1

Leads
7 8

Generalization (Inheritance) Generalization (Inheritance) e.g.

Child class is a special case of the parent


class Circle

SuperClass

GraphicCircle

SubClass1 SubClass2

9 10

Inheritance - I mplementation Abstract Class

public class Circle { Shape

public class GraphicCircle extends Circle {


Circle Rectangle
}

11 12
Abstract class and method
Abstract Methods (Operations)
Implementation
public abstract class Shape {
Shape public abstract draw(); //declare
draw() without implementation
………
}

public class Circle {


public draw(){
Circle Rectangle …….
}
draw() draw() …..
}
13 14

Class Relationships Realization- Interface

Association


Interface is a set of operation the class


carries out


Generalization


Realization
Keyboard Keyboard


Dependency brandName <<interface>> brandName


numOfKeys TypeWriter numOfKeys
OR
ctl() ctl()
keyStroke() TypeWriter
pageDown() pageDown()

15 16

Realization - Implementation Class Relationships

public interface TypeWriter {


void keyStroke()


Association
}


Generalization
public class KeyBoard implements TypeWriter {


Realization
public void keyStroke(){
………


Dependency
}
}

17 18
Dependency Dependency cont


Change in specification of one class can 

Dependency relationship can be used to


change the other class. This can happen show relationships between classes and
when one class is using another class. objects.
f> >
ceO circleA:Circle
nst an
<i
Circle <

Circle
Point
Move(p:Point) <<
ins
t an
ce
Of circleB:Circle
>>

19 20

Class Diagrams Class Diagram - Example

Draw a class diagram for a information


The UML class diagram consists


modeling system for a school.


of several Classes, connected

School has one or more Departments.


Department offers one or more Subjects.
with Relationships.

A particular subject will be offered by only one


department.

Department has instructors and instructors can work


for one or more departments.

Student can enrol in upto 5 subjects in a School.


Instructors can teach upto 3 subjects.


The same subject can be taught by different


instructors.
21

Students can be enrolled in more than one school. 22

Class Diagram - Example Class Diagram - Example


School has one or more Departments. 

Department has Instructors and instructors can


work for one or more departments.
School Department
1 has 1..*
Instructor Department
1..* assigned to 1..*

Department offers one or more Subjects.


A particular subject will be offered by only one

Student can enrol in upto 5 Subjects.


department.

Department Subject Student Subject


1 offers 1..* * takes 0..5
23 24
Class Diagram - Example Class Diagram - Example

Instructors can teach up to 3 subjects.

Students can be enrolled in more than one


The same subject can be taught by different school.


instructors.

1..* *
Instructor Subjects Student School
teaches 1..3 member 1..*

25 26

Class Diagram Example Object Diagram


has

School Department

Object Diagram shows the


1 1..* 1..*
relationship between objects.
1…* 1
offeres
assignedTo
member

Unlike classes objects have a state.

* 1..* 1..*

attends teaches Instructor


Student Subject
* 1..5 1..3 1..*

27 28

Object Diagram - Example


c1: Company

d1: Department d2: Department

name= “Sales” name= ”R&D”

manager employee

p1: Persont p2: Person

name= “John” name= “David”


29

Вам также может понравиться