UML Intro and Class Models
UML Intro and Class Models
Static Dynamic
Class diagram State diagram
(Object diagram) Collaboration diagram
Component diagram (Sequence diagram)
(Deployment diagram) (Activity diagram)
Usage survey
Use Case
Class diagram
Sequence diagram
Point
x
Point
y
Move
Point
- x: int
- y: int
+ move(dx: int, dy: int): void
Example
A document defined by classes at three different abstraction levels
Document
Document Pages[]
nPages
display
Document
- Pages: array of Page
- nPages: int
+ display(k:int, p:Page): void
UML Class Diagrams
Represent the (static) structure of the system
General In Java
Name Name
State Variables
Behavior Methods
Exercise
Draw a class diagram for the following Java code
class Person {!
private String name;!
private Date birthday;!
public String getName() {!
// …!
}!
public Date getBirthday() {!
// …!
} !
}!
A counter class
Counter class Counter{!
private counter: integer;!
- counter: integer public integer display()!
{return counter};!
public void tic()!
+ display: integer {counter = counter + 1};!
+ tic: void public void reset()!
+ reset: void
{counter = 0};!
A class in UML }!
A corresponding class
in a programming language
c3:Counter p:Printer
0..* 1
Student Faculty
advisee advisor
Multiplicity of Associations
Some relationships may be quantified
Multiplicity denotes how many objects the
source object can legitimately reference
Notation
* 0, 1, or more
5 5 exactly
5..8 between 5 and 8, inclusive
5..* 5 or more
Multiplicity of Associations
Many-to-one
Bank has many ATMs, ATM knows only 1 bank
One-to-many
Inventory has many items, items know 1 inventory
Associations w/ Navigation Information
Can indicate direction of relationship
Represented by solid line with arrowhead
enroll
Student Course
takes
Student Course
10..300 1..5
Association Example
- Multiplicity
• A teacher teaches 1 to 3 courses
• 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
Exercise
Explain the meaning of this diagram
1
1
Teacher
advisor