Introduction To UML
Introduction To UML
Introduction to
Unified Modeling Language
(UML)
Heavily based on UML Slides made available at following locations:
https://www.cs.drexel.edu/~spiros/teaching/CS575/slides/uml.ppt
https://www.cs.ucf.edu/~turgut/COURSES/EEL5881_SEI_Fall07/UML_Lecture.ppt
WHAT IS UML AND WHY WE USE UML?
UML → “Unified Modeling Language”
Modeling: Describing a software system at a high
level of abstraction
Unified: UML has become a world standard
Object Management Group (OMG): www.omg.org
It is a industry-standard graphical language for specifying,
visualizing, constructing, and documenting the artifacts of
software systems
The UML uses mostly graphical notations to express the OO
analysis and design of software projects.
Simplifies the complex process of software design
UML: UNIFIED MODELING LANGUAGE
attributes
operations
CLASS ATTRIBUTES
Person
/ age : Date
CLASS ATTRIBUTES (CONT’D)
Person
name : String
address : Address
birthdate : Date
ssn : Id
You can specify an operation by stating its signature: listing the name, type, and default
value of all parameters, and, in the case of functions, a return type.
DEPICTING CLASSES
When drawing a class, you needn’t show attributes and operation in every diagram.
name : String
birthdate : Date
Person ssn : Id
SmokeAlarm
Responsibilities
• dependencies
• generalizations
• associations
DEPENDENCY RELATIONSHIPS
A dependency indicates a semantic relationship between two or
more elements. The dependency from CourseSchedule to Course exists because Course
is used in both the add and remove operations of CourseSchedule.
CourseSchedule
Course
add(c : Course)
remove(c : Course)
GENERALIZATION RELATIONSHIPS
Person A generalization connects a subclass
to its superclass. It denotes an
inheritance of attributes and behavior
from the superclass to the subclass and
indicates a specialization in the subclass
of the more general superclass.
Supertype
Student
Subtype1 Subtype2
GENERALIZATION RELATIONSHIPS (CONT’D)
UML permits a class to inherit from multiple superclasses, although some programming
languages (e.g., Java) do not permit multiple inheritance.
Student Employee
TeachingAssistant
ASSOCIATION RELATIONSHIPS
If two classes in a model need to communicate with each other, there must be link
between them.
Student Instructor
ASSOCIATION RELATIONSHIPS (CONT’D)
We can indicate the multiplicity of an association by adding multiplicity adornments to
the line denoting the association.
Student Instructor
1..*
ASSOCIATION RELATIONSHIPS (CONT’D)
The example indicates that every Instructor has one or more Students:
Student Instructor
1..*
ASSOCIATION: MULTIPLICITY AND ROLES
student
1 *
University Person
0..1 *
employer teacher
Multiplicity Role
Symbol Meaning
1 One and only one Role
0..1 Zero or one “A given university groups many people;
M..N From M to N (natural language)
some act as students, others as teachers.
A given student belongs to a single
* From zero to any positive integer university; a given teacher may or may not
0..* From zero to any positive integer be working for the university at a particular
1..* From one to any positive integer time.”
ASSOCIATION: MODEL TO IMPLEMENTATION
* 4
Student Course
has enrolls
Class Student {
Course enrolls[4];
}
Class Course {
Student have[];
}
ASSOCIATION RELATIONSHIPS (CONT’D)
We can also indicate the behavior of an object in an association (i.e., the role of an
object) using rolenames.
membership
Student Team
1..* 1..*
ASSOCIATION RELATIONSHIPS (CONT’D)
member of
1..* 1..*
Student Team
1 president of 1..*
ASSOCIATION RELATIONSHIPS (CONT’D)
Router DomainNameServer
ASSOCIATION RELATIONSHIPS (CONT’D)
Associations can also be objects themselves, called link classes or an association classes.
Registration
modelNumber
serialNumber
warrentyCode
Product Warranty
ASSOCIATION RELATIONSHIPS (CONT’D)
next
LinkedListNode
previous
ASSOCIATION RELATIONSHIPS (CONT’D)
We can model objects that contain other objects by way of special associations
called aggregations and compositions.
Engine
Car
Transmission
OO RELATIONSHIPS: AGGREGATION
Container Class
Aggregation:
Class C expresses a relationship among instances of related
classes. It is a specific kind of Container-
AGGREGATION
Containee relationship.
Apples Milk
ASSOCIATION RELATIONSHIPS (CONT’D)
A composition indicates a strong ownership and coincident lifetime of parts by the
whole (i.e., they live and die as a whole). Compositions are denoted by a filled-
diamond adornment on the association.
Scrollbar
1 1
Window Titlebar
1 1
Menu
1 1 .. *
OO Relationships: Composition
Whole Class
Class W Association
Models the part–whole relationship
Composition
Class P1 Class P2 Also models the part–whole relationship but, in
addition, Every part may belong to only one
whole, and If the whole is deleted, so are the
Part Classes parts
Example Example:
A number of different chess boards: Each square
belongs to only one board. If a chess board is
thrown away, all 64 squares on that board go as well.
Figure 16.7
The McGraw-Hill Companies, 2005
AGGREGATION VS. COMPOSITION
Aggregations
may form "part of" the association, but may not be essential to it. They
may also exist independent of the aggregate. e.g. Apples may exist
independent of the bag.
INTERFACES
An interface is a named set of operations that
specifies the behavior of objects without showing
their inner structure. It can be rendered in the model
by a one- or two-compartment rectangle, with the
<<interface>>
stereotype <<interface>> above the interface
ControlPanel
name.
INTERFACE SERVICES
getChoices : Choice[]
makeChoice (c : Choice)
getSelection : Selection
INTERFACE REALIZATION RELATIONSHIP
A realization relationship connects a class
<<interface>> with an interface that supplies its
ControlPanel behavioral specification. It is rendered
by a dashed line with a hollow triangle
specifier towards the specifier.
implementation
VendingMachine
PARAMETERIZED CLASS
<<bind>>(Name
)
DeansList
ENUMERATION
<<exception>> <<exception>>
KeyException SQLException
GOOD PRACTICE: CRC CARD
Class Responsibility Collaborator
easy to describe how classes work by moving cards around; allows to
quickly consider alternatives.
CLASS DIAGRAM
Compiler
FrontEnd BackEnd
PACKAGES (CONT’D)
Classes in the BackEnd package now have access to the classes in the FrontEnd
package.
Compiler
FrontEnd BackEnd
PACKAGES (CONT’D)
JavaCompiler Java
COMPONENT DIAGRAM
Component diagrams are one of the two kinds of diagrams found in modeling the
physical aspects of an object-oriented system. They show the organization and
dependencies between a set of components.
Use component diagrams to model the static implementation view of a system. This
involves modeling the physical things that reside on a node, such as executables,
libraries, tables, files, and documents.
- The UML User Guide, Booch et. al., 1999
COMPONENT DIAGRAM
path.dll collision.dll
driver.dll
version = 8.1.3.2
IDrive
ISelfTest
COMPONENT DIAGRAM
signal.h signal.h signal.h
version = 3.5 version = 4.0 version = 4.1
“parent” “parent”
signal.cpp
interp.cpp version = 4.1
Modeling source code.
[Booch, 99]
irq.h device.cpp
DEPLOYMENT DIAGRAM
Deployment diagrams are one of the two kinds of diagrams found in modeling
the physical aspects of an object-oriented system. They show the configuration of
run-time processing nodes and the components that live on them.
Use deployment diagrams to model the static deployment view of a system. This
involves modeling the topology of the hardware on which the system executes.
- The UML User Guide, [Booch,99]
DEPLOYMENT DIAGRAM
A component is a physical unit of implementation with well-defined interfaces that is
intended to be used as a replaceable part of a system. Well designed components
do not depend directly on other components, but rather on interfaces that components
support.
- The UML Reference Manual, [Rumbaugh,99]
component
spell-check
Dictionary interfaces
synonyms
DEPLOYMENT DIAGRAM
stereotyped
<<database> component
> Account
usage dependency
component
ATM-GUI
[Rumbaugh,99]
realization dependency
DEPLOYMENT DIAGRAM
server:HostMachine
<<database>>
clientMachine:PC
:Planner
USE CASE
“A use case specifies the behavior of a system or a part of a system, and is a
description of a set of sequences of actions, including variants, that a system performs
to yield an observable result of value to an actor.”
- The UML User Guide, [Booch,99]
Student
USE CASE (CONT’D)
Actors can participate in a generalization relation with other actors.
Student Person
USE CASE (CONT’D)
Actors may be connected to use cases
only by associations.
Student
USE CASE (CONT’D)
Here we have a Student interacting with the Registrar and the
Billing System via a “Register for Courses” use case.
Billing System
Registrar
USE-CASE DIAGRAMS
Include: a dotted line labeled <<include>> beginning at base
use case and ending with an arrows pointing to the include use
case. The include relationship occurs when a chunk of
behavior is similar across more than one use case. Use
“include” instead of copying the description of that behavior.
<<include>>
<<extend>>
USE-CASE DIAGRAMS
USE-CASE DIAGRAMS
Both Make Appointment and
Request Medication include
Check Patient Record as a
subtask (include)
simple state
Start End
Unpaid Paid
Invoice created paying Invoice destroying
STATE DIAGRAMS (TRAFFIC LIGHT EXAMPLE)
Yellow
Green
Event
STATE MACHINE – COURSE SCHEDULING
download course offerings downloading
unscheduled
make a course selection
selecting
verifying
select another course
check schedule
sign schedule
checking schedule
scheduled
SEQUENCE DIAGRAM
A sequence diagram is an interaction diagram that emphasizes the time ordering of
messages. It shows a set of objects and the messages sent and received by those
objects.
Graphically, a sequence diagram is a table that shows objects arranged along the X
axis and messages, ordered in increasing time, along the Y axis.
* prepare()
An iteration marker, such as * (as shown), or *[i
= 1..n] , indicates that a message will be
repeated as indicated.
Iteration
marker
SEQUENCE DIAGRAM(MAKE A PHONE CALL)
Picks up
Dial tone
Dial
Picks up
Hello
SEQUENCE DIAGRAM:OBJECT INTERACTION
A B
Self-Call: A message that an
Synchronous
Object sends to itself.
[condition] remove()
Condition
*[for each] remove()
Iteration
Self-Call
SEQUENCE DIAGRAMS – OBJECT LIFE SPANS
Creation
Create message A
4 : title returned ()
•The horizontal dimension shows the
objects participating in the interaction. 5: hold title ()
5 : title available ()
prepare()
Condition
* prepare()
Object
check()
Creation
COLLABORATION DIAGRAM
A collaboration diagram emphasizes the relationship of the objects that participate in
an interaction. Unlike a sequence diagram, you don’t have to show the lifeline of an
object explicitly in a collaboration diagram. The sequence of events are indicated by
sequence numbers preceding messages.
Object identifiers are of the form objectName : className, and either the objectName
or the className can be omitted, and the placement of the colon indicates either an
objectName: , or a :className.
COLLABORATION
: Order Entry Window
DIAGRAM Object
Sequence Number
1: prepare() Message
: Order Self-Delegation
5: needToReorder()
[Fowler,97]
INTERACTION DIAGRAMS: COLLABORATION DIAGRAMS
start
6: remove reservation
1: look up
2: title data
4 : title returned
Catalog
5 : hold title
Both a collaboration diagram and a sequence diagram derive from the same information
in the UML’s metamodel, so you can take a diagram in one form and convert it into the
other. They are semantically equivalent.
Use a sequence diagram when the transfer of information is the focus of attention
Multiple Trigger
Check
Cancel Authorize
Line
Order [failed]
Payment
Item
Assign to
Order
Synchronization Condition
[need to
reorder] Reorder
Item
[stock assigned to
all line items and
payment authorized]
Dispatch
Order
SOME REFERENCES
https://www.cs.drexel.edu/~spiros/teaching/CS575/slides/uml.ppt
https://www.cs.ucf.edu/~turgut/COURSES/EEL5881_SEI_Fall07/UML_Lecture.ppt
Fowler, Martin, Kendall Scott, UML Distilled (Applying the Standard Object Modeling
Language), Addison Wesley, 1997.