Unified Modeling Language A Brief Introduction – 2015

advertisement
Unified Modeling Language
A Brief Introduction
jonas.kvarnstrom@liu.se – 2015

In the early 1990s, three common OO modeling approaches
 James Rumbaugh's
Object-modeling technique (OMT)
 Grady Booch's Booch method
 Ivar Jacobson’s
Object-Oriented Software Engineering
(OOSE)
2
jonkv@ida
History

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
3
jonkv@ida
History (2)

We will focus on class diagrams!
4
jonkv@ida
UML Diagram Types

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
5
jonkv@ida
Usage Guidelines

6
General structure of a class:
ArrayList
Class Name
elements: Object[]
length: int
Attributes
size() : int
get(int amount): Object
add(Object element): Object
set(int index, Object element): void
Operations (methods)
Static members: Underlined!
Colors are not part of the standard –
added here for clarity!
jonkv@ida
Simple Class Diagram

7
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
jonkv@ida
Visibility Markers

8
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
jonkv@ida
Interfaces

9
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
LinkedList
List <<interface>>
+size(): int
+get(int amount): Object
+add(Object element): Object
+set(int index, Object element): void
ArrayList
SkipList
–head: Object
–tail: LinkedList
–elements: Object[]
–length: int
…
+size() : int
…
+size() : int
+get(int amount): Object
+add(Object element): Object
+set(int index,Object element): void
+size() : int
…
jonkv@ida
Realization

10
Class Relationship: Generalization (inheritance)
 List specializes Collection (adds new requirements, new methods)
 Collection generalizes List
 Ordinary line, unfilled arrowhead
Collection <<interface>>
+size(): int
+add(Object element): Object
+contains(Object element): boolean
List <<interface>>
+get(int index): Object
+set(int index, Object element): void
jonkv@ida
Generalization

11
Class Relationship: Generalization (inheritance)
 GraphicCircle specializes Circle
 Circle generalizes GraphicCircle
 Ordinary line, unfilled arrowhead
Circle
+x, y, r: double
+getArea(): double
GraphicCircle
+outline, fill: Color
+draw(DrawWindow): void
jonkv@ida
Generalization 2

12
Instance Relationship: Composition
 A hand is part of a person
 If we "remove" the person, its hands also removed
 Line with filled diamond
Person
Hand
 May add multiplicity
▪ Every person has two hands, every hand is part of one person
Person
1
2
Hand
Omit fields/methods
when they are not relevant!
jonkv@ida
Composition
13

Instance Relationship: Aggregation

Alternative 1:
 In our model, a car is permanently linked to its wheels
Car

1
0..*
Wheel
Alternative 2:
 In our model, we can buy new wheels, or even swap wheels between cars
 Wheels can exist without cars
Car
0..1
0..*
Wheel
jonkv@ida
Aggregation

14
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
Person
0..*
0..*
Magazine
 May name an association (or composition / aggregation)
Person
0..*
subscribes
0..*
Magazine
jonkv@ida
Association
15
jonkv@ida
Other UML Diagrams
Download