2
jonk
v@id
ajo
nkv@
ida
2History In the early 1990s, three common OO modeling approaches James Rumbaugh's
Object-modeling technique (OMT)
Grady Booch's Booch method
Ivar Jacobson’sObject-Oriented Software Engineering(OOSE)
3
jonk
v@id
ajo
nkv@
ida
3History (2) 1995: All three employed at Rational Software Known as The Three Amigos
1996: Too many modeling languages slower adoption of OO Wanted a non-proprietary language using the best parts Formed an international consortium
Result: Unified Modeling Language, UML Not a development method, just a language
Used to build a system model Part of this model can be represented
as various forms of diagrams
4
jonk
v@id
ajo
nkv@
ida
4UML Diagram Types We will focus on class diagrams!
5
jonk
v@id
ajo
nkv@
ida
5Usage Guidelines Why use class diagrams?
To design software before coding▪ Create a broad structure, check that it is consistent and reasonable
To help you understand existing code▪ Create a structural overview▪ Can be faster to construct and to understand a diagram
than a long text describing the same thing
How should they be used? Less is more
▪ Focus!▪ Illustrate one coherent subsystem at a time▪ Include only as much as you need
6
jonk
v@id
ajo
nkv@
ida
6Simple Class Diagram General structure of a class:
ArrayList
elements: Object[]length: int
size() : intget(int amount): Objectadd(Object element): Objectset(int index, Object element): void
Class Name
Attributes
Operations (methods)
Static members: Underlined!Colors are not part of the standard –
added here for clarity!
7
jonk
v@id
ajo
nkv@
ida
7Visibility Markers Visibility markers before names + Public # Protected – Private ~ Package / Derived (computed from other attributes) Also, static methods or fields are underlined
ArrayList
–elements: Object[]–length: int
+size() : int+get(int amount): Object+add(Object element): Object+set(int index, Object element): void
8
jonk
v@id
ajo
nkv@
ida
8Interfaces General structure of an interface: Interface name in italics Marked with the <<interface>> ”stereotype”
List <<interface>>
+size(): int+get(int amount): Object+add(Object element): Object+set(int index, Object element): void
9
jonk
v@id
ajo
nkv@
ida
9Realization Class Relationships: Realization An interface is simply a description Classes realize the interface:
Provide a concrete implementation Dashed arrow, unfilled arrowhead Members shown:
▪ Where they are declared for the first time▪ Where they are implemented / overridden
List <<interface>>
+size(): int+get(int amount): Object+add(Object element): Object+set(int index, Object element): void
ArrayList
–elements: Object[]–length: int
+size() : int+get(int amount): Object+add(Object element): Object+set(int index,Object element): void
LinkedList
–head: Object–tail: LinkedList
+size() : int…
SkipList
…
+size() : int…
10
jonk
v@id
ajo
nkv@
ida
10Generalization Class Relationship: Generalization (inheritance) List specializes Collection (adds new requirements, new methods) Collection generalizes List Ordinary line, unfilled arrowhead
List <<interface>>
+get(int index): Object+set(int index, Object element): void
Collection <<interface>>
+size(): int+add(Object element): Object+contains(Object element): boolean
11
jonk
v@id
ajo
nkv@
ida
11Generalization 2 Class Relationship: Generalization (inheritance) GraphicCircle specializes Circle Circle generalizes GraphicCircle Ordinary line, unfilled arrowhead
GraphicCircle
+outline, fill: Color
+draw(DrawWindow): void
Circle
+x, y, r: double
+getArea(): double
12
jonk
v@id
ajo
nkv@
ida
12Composition Instance Relationship: Composition A hand is part of a person If we "remove" the person, its hands also removed Line with filled diamond
May add multiplicity▪ Every person has two hands, every hand is part of one person
Person Hand
Person Hand1 2
Omit fields/methodswhen they are not relevant!
13
jonk
v@id
ajo
nkv@
ida
13Aggregation Instance Relationship: Aggregation
Alternative 1: In our model, a car is permanently linked to its wheels
Alternative 2: In our model, we can buy new wheels, or even swap wheels between cars Wheels can exist without cars
Car Wheel1 0..*
Car Wheel0..1 0..*
14
jonk
v@id
ajo
nkv@
ida
14Association Instance Relationship: Association A person subscribes to zero or more magazines A magazine has zero or (hopefully) more subscribers The connection is not as close as between a car and its wheels
May name an association (or composition / aggregation)
Person Magazine
Person Magazinesubscribes
0..* 0..*
0..* 0..*
15
jonk
v@id
ajo
nkv@
ida
15Other UML Diagrams