Title: What is UML Unified Modeling Language
1What is UML (Unified Modeling Language)?
- UML is a set of graphical notations used to model
software system - A picture is worth a thousand words
- Equivalent to blueprint used by construction
engineers - Prior to 1995, many different modeling languages
- Confusing, time to establish a common standard
- Current version UML version 2 (in year 2003)
- You can use Visio to draw the diagrams
- Ref UML Distilled (3rd Edition) Martin Fowler
2Ways of using the UML
- Sketch
- For communicating a design
- Only highlight the essential components
- Blueprint
- Round-trip engineering
- Class has one-to-one mapping with code
- Class diagram -gt code generation -gt class diagram
- Programming language
- UML diagram -gt code generation
3UML2 diagrams
Class Diagram
Component Diagram
Composite Diagram
Structure Diagram
Deployment Diagram
Object Diagram
Package Diagram
Diagram
Activity Diagram
Sequence Diagram
Use Case Diagram
Behavior Diagram
Communication Diagram
State Diagram
Interaction Diagram
Interaction Overview Diagram
Timing Diagram
4Class diagram
- The most widely used UML diagram
- Show static relationships between classes
Association
Class Name of A Attributes Operations
Class Name of B Attributes Operations
Role of A
Role of B
Name of Association
1
1..
multiplicity
5Attribute
- visibility nametype multiplicitydefault
property-string - Example -dueDateDate 0..1 null readOnly
- Visibility
- (public) - (private)
- (protected) (package)
- - (static)
- Multiplicity
- 1 (exactly one) (any number)
- 0..1 (either zero or one)
- property-string
- optional
6Operation
- visibility name(param-list) return-type
property-string - Example Foo (valueint) void query
- property-string
- query get value without changing the system
state - abstract abstract operation, implemented by
subclass - ExceptionXXX name the exception returned
7Association
- Dependency
- A depends on B
- Change Bs interface may affect A
- Navigable association
- A has a B
- implicitly implies dependency
- Bidirectional association
- A has a B, and B has an A
- Unidirectional association
- A and B has relation
- But direction is unspecified
A
B
A
B
A
B
A
B
8Dependency
A
B
- A depends (or use) on B
- But A does not has an instance of B as part of
its state - public class A
- public void foo(B b) . . . //OK
- public void bar()
- B b new B() //OK
-
- private B b //not OK, has an instance of B
-
9Association
- A stronger dependency
- A depends (or use) on B
- A has an instance of B as part of its state
- public class A
- private B b //OK
-
- Navigable association implicitly implies
dependency
A
B
10- Generalization
- Realization
- Provides the implementation
BaseClass
DerivedClass
AbstractClass
DerivedClass
11- Attributes and associations
- Both represents the same thing
- Choose the one that makes your diagram easier to
understand
0..1
Book dueDateDate0..1
Book
Date
Date is an attribute of Book
Date is associated with Book
12Aggregation and Composition
Car
Wheel
- Aggregation
- Part-of relationship
- Shared by other objects, therefore the whole can
be deleted, but not the part - E.g. Car has Wheels
- Composition
- Stronger type of aggregation
- The part cannot be shared
- Delete the whole, then the part must be deleted
as well - Hard to tell the difference between association
and aggregation - Fowler suggests always to use association instead
of aggregation
Rectangle
Point
13Interface and Abstract Classes
ltltinterfacegtgt List
Stereotype
Get
generalization
ltltinterfacegtgt SortedList
Client
dependency
Sort
implementation
AbstractArrayList
Get Sort
Concrete method
Abstract method (italic)
ArrayList
Overriding
Get Sort
14Ball-and-socket Notation (UML2)
- Previous example, alternative representation
- Qualified association
- To model concept like associative array,
dictionary
SortedList
ArrayList
Client
List
1
StudentInfo
Claslist
1
1
ClassList
StudentInfo
Id
Qualified association
15Association Class
- To model the association between two classes. The
two classes may have many-to-many association,
but there can be only one instance of association
class between objects of the two classes - Example
1..
1..
1..
Person
Share
Company
1..
1..
Person
Company
Share quantity
Better, association class add extra constraint
16Association Class
- OK
- Not allowed for association class
personA
CompanyA
personB
CompanyB
personA
CompanyA
personB
CompanyB
17- A person can take up several roles (director,
investor) in a company, cannot be modeled by
association class - More appropriate
1..
1..
Person
Company
Role
1..
1..
1..
1..
Person
Role
Company
18Constraints
- Free format, just put anything you like inside
to describe constraints in your model
ordered
ClassList
Student
Menu
or
Soup
Salad
MainCourse
Dessert
19Template (Parameterized) Class
- class Set ltclass Tgt
- public void Insert(T member) ...
- public void Remove(T member) ...
-
T
Set Insert(T) Remove(T)
Template parameter
20Package Diagrams
- Each package represents a namespace
- Consists of a group of classes, larger unit
- Example System.IO
System.IO
21Package Diagram
- Avoid dependency cycle, at least localized it
- Cycle in A, B, and C, but not in A, B and D
Package A
Package B
Package C
Package D
22Object Diagrams
- To show a snapshot of the objects
- Object instance nameclass name
MapSite
Class diagram
Room
Wall
Door
r1Room roomNumber1
Object diagram
side0Wall
side1Wall
side2Wall
side3Door
23Implementing Packages
GameApplication
AbstractGameEngine
implement
PacMan
LittleFighter
24Component Diagrams
- What is a component?
- A piece of software that can be independently
purchased and upgraded, and can integrate
seamlessly into customers existing software
seamlessly
Librarian
Librarian
UML 2 notation
UML 1 notation
25Component Diagrams
Library
DB
UI
Librarian
Database
26Deployment Diagrams
- To show the physical layout of the system, and
the software that run on what pieces of hardware
Linux server
TCP/IP
TCP/IP
component connection node
DB
Librarian
A Windows PC
Oracle server
UI
Database
27Deployment diagram
- Node
- Something that can host the software
- Artifact
- The physical manifestation of software, such as
files, assemblies, DLL, or scripts - Artifact is usually a component
28Composite Structures
- Support hierarchical modeling of a class
structure
Control UI
Input
port
Control API
Control UI
MediaPlayer
multiplicity
1
MediaPlayer
UI
MediaFilter
Control API
Video stream
Display driver
Output
Video stream
Display driver
29UML Interaction Diagrams (Behavior Model)
- Sequence diagram
- The most common kind of interaction diagram
- Capture the behavior of a scenario
anObjectClassName
Lifeline (dotted line)
Synchronous call
Activation (rectangle)
Asynchronous call (UML gt 1.4)
new
obj
Create object
Asynchronous call (UML lt 1.3)
return (optional)
30Check-out scenario KnowFine()
iteration
guard
31Note
- iteration marker for all objects
- condition
- the message is sent only if the condition is true
- self-delegation
- an message that an object sends to itself
- About loops and conditionals
- Sequence diagram is not good at it, better off
with activity diagram or the code itself - UML2 uses a new notation call interaction frames
to support these functions
32Interaction Frame
- alt alternative, executes only if condition is
met
33Communication Diagrams
- Known as Collaboration Diagram in UML 1.x
- Contain the same info as the sequence diagram
- Sequence diagram is more common, communication
diagram may good well with CRC cards
34Nested number system (legal UML)
35Not official numbering system, but commonly used
36Activity Diagrams
- Similar to flowcharts, but supports parallel
behavior
initial state
fork
state
join
decision
guard
final state
37Swimlanes
- Each swimlane shows the activities within a class
38Signals
- Signal send
- To send a message to an activity in another
process - Signal receipt
- Accepting an event message from another process
Callback Borrower
signal send
state
ReserveBook
time signal
Overdue
Email To Borrower
Callback Received
signal receipt
39State Machine Diagrams
- Describe the states and lifetime of an object
- State diagram of a Book
initial state
state
Borrowed
Returned
transition
final state
40History state
H
- The remembered substate before last transition
- E.g. computer screen goes blank after time-out,
back to original state at keystroke or mouse
movement
Working
H
substate
Update Display
Process Input
Wait for Input
Keyboard or mouse movement
time-out
Sleeping
41Interaction Overview Diagrams
- Mix sequence diagram with activity diagram
Check fine
Check borrow limit
42Timing Diagrams
- Shows the timing of states change of one or more
objects, like those use in electronic engineering
lecture
Mid-term
lecture
Course
gt6 weeks
gt4 weeks
43Use of UML
- Requirement and analysis
- Use cases
- Describe how users interact with the system
- Class diagram
- Build up vocabulary, show the conceptual model of
the system - Activity diagram
- Like flowchart, show the work flow of the system
- State diagram
- For objects that have complex life cycle
44Use of UML
- Design
- Class diagram
- Fuller and more detailed
- Sequence diagram
- To describe the most important scenarios form use
cases - Package diagram
- To show the large-scale organization of the
system - State diagram
- Deployment diagram
- To show the physical layout of the software
45Documentation
- Use your good sense
- Dont overuse UML, too many diagrams with too
much details make the documents difficult to
understand - Use diagrams to show the important architecture,
e.g. - Package diagram show road map of the system
- Class diagram within each package, provide more
detailed information, be selective - Deployment diagram show physical layout
- State diagram only for complex object
- Detailed documentation can be generated from the
code - JavaDoc for Java and Visual Studio for C