Professional Documents
Culture Documents
UML Class Diagrams: CSE 403: Software Engineering, Spring 2015
UML Class Diagrams: CSE 403: Software Engineering, Spring 2015
courses.cs.washington.edu/courses/cse403/15sp/
Emina Torlak
emina@cs.washington.edu
Outline
• Designing classes
• Overview of UML
• UML class diagrams
• Syntax and semantics
• Examples
2
design
design phase: from requirements to code
Software design
4
Software design
4
Software design
4
How to design classes?
5
Describing designs with CRC cards
6
Describing designs with UML diagrams
7
basics
describing designs with UML: an overview
What is UML?
9
What is UML?
9
What is UML?
9
UML: Unified Modeling Language
10
Uses for UML
11
Uses for UML
11
Uses for UML
11
Uses for UML
11
learn
UML class diagrams
What is a UML class diagram?
13
Diagram of a single class
Rectangle
- width: int
- height: int
/ area: double
Student
- name: String
- id: int
- totalStudents: int
# getID(): int
~ getEmail(): String
14
Diagram of a single class
Rectangle
Student
- name: String
- id: int
- totalStudents: int
# getID(): int
~ getEmail(): String
14
Diagram of a single class
Rectangle
Student
- name: String
- id: int
- totalStudents: int
# getID(): int
~ getEmail(): String
14
Diagram of a single class
Rectangle
# getID(): int
~ getEmail(): String
14
Class attributes (fields, instance variables)
Student
- name: String
- id: int
- totalStudents: int
# getID(): int
~ getEmail(): String
15
Class attributes (fields, instance variables)
# getID(): int
~ getEmail(): String
15
Class attributes (fields, instance variables)
# getID(): int
~ getEmail(): String
15
Class attributes (fields, instance variables)
15
Class operations / methods
Student
- name: String
- id: int
- totalStudents: int
# getID(): int
~ getEmail(): String
16
Class operations / methods
# getID(): int
~ getEmail(): String
16
Class operations / methods
# getID(): int
~ getEmail(): String
16
Class operations / methods
# getID(): int
~ getEmail(): String
16
Class operations / methods
16
Comments
Cloneable is a tagging
interface with no
«interface»
Cloneable
methods. The clone()
methods is defined in
the Object class.
17
Relationships between classes
18
Generalization relationships «interface»
Shape
+ getArea(): double
RectangularShape
- width: int
- height: int
/ area: double
Rectangle
- x: int
- y: int
19
Generalization relationships «interface»
Shape
+ getArea(): double
Rectangle
- x: int
- y: int
19
Generalization relationships «interface»
Shape
+ getArea(): double
Rectangle
- x: int
- y: int
19
Generalization relationships «interface»
Shape
+ getArea(): double
Rectangle
- x: int
- y: int
19
Generalization relationships «interface»
Shape
+ getArea(): double
19
Associational (usage) relationships
Class A Class B
1..* k
contains
20
Associational (usage) relationships
20
Associational (usage) relationships
20
Associational (usage) relationships
20
Association multiplicities
• One-to-one Car
1 1
Engine
• Each car has exactly one engine.
• Each engine belongs to exactly one car.
• One-to-many Book Page
1 *
• Each book has many pages.
• Each page belongs to exactly one book.
21
Association types
Car Engine
1 1
22
Association types
22
Association types
22
Association types
22
Aggregation / composition example
MovieTheater BoxOffice
1 1
*
Movie
23
Class diagram example: video store
Multiplicity
Customer 1
Class
Aggregation
Rental Invoice
Abstract class
1..*
Rental Item 1 0..1
Generalization Composition
Association
Checkout Screen
DVD VHS Game
24
Class diagram example: people
25
Class diagram example: student
StudentBody Student
1 100
- firstName : String
+ main (args : String[]) - lastName : String
- homeAddress : Address
- schoolAddress : Address
+ toString() : String
Address
- streetAddress : String
- city : String
- state : String
- zipCode : long
+ toString() : String
26
Tools for creating UML diagrams
• Violet (free)
• http://horstmann.com/violet/
• Rational Rose
• http://www.rational.com/
• Visual Paradigm UML Suite (trial)
• http://www.visual-paradigm.com/
• There are many others, but most are commercial
27
What (not) to use class diagrams for
28
What (not) to use class diagrams for
28
What (not) to use class diagrams for
28
Summary
29