4 - UML Lecture

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

Unified Modeling Language

(UML)

02/25/2014
UML 1
Outline
 What is UML and why we use UML?

 How to use UML diagrams to design


software system?

 What UML Modeling tools we use today?

02/25/2014 UML 2
Unified Modeling Language (UML) and
Modeling
 UML is a graphical notation useful for
OO analysis and design
 Allows representing various aspects of
the system
 Various notations are used to build
different models for the system
 OOAD methodologies use UML to
represent the models they create

02/25/2014 UML 3
Modeling
 Modeling is used in many disciplines –
architecture, aircraft building, …
 A model is a simplification of reality
 “All models are wrong, some are useful”
 A good model includes those elements
that have broad effect and omits minor
elements
 A model of a system is not the system!
02/25/2014 UML 4
Why build models?
 Models help us visualize a system
 Help specify the system structure
 Gives us a template that can guide the
construction
 Document the decisions taken and their
rationale

02/25/2014 UML 5
Modeling
 Every complex system requires multiple
models, representing different aspects
 These models are related but can be
studied in isolation
 Eg. Architecture view, electrical view,
plumbing view of a building
 Model can be structural, or behavioral

02/25/2014 UML 6
What is UML and Why we use UML?

 More description about UML:


 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

02/25/2014 UML 7
What is UML and Why we use UML?

 Why we use UML?


 Use graphical notation: more clearly than natural language
(imprecise) and code (too detailed).

 Help acquire an overall view of a system.

 UML is not dependent on any one language or technology.

 UML moves us from fragmentation to standardization.

02/25/2014 UML 8
What is UML ?
 UML - Unified Modeling language
 UML is a modeling language, not a methodology or
process
 Fuses the concepts of the Booch, OMT, OOSE methods
 Developed by Grady Booch, James Rumbaugh and Ivar
Jacobson at Rational Software.
 Accepted as a standard by the Object Management Group
(OMG), in 1997.

02/25/2014 UML 9
More on UML...
UML is a modeling language for visualising,
specifying, constructing and documenting
the artifacts of software systems.
Visualising - a picture is worth a thousand
words; a graphical notation articulates and
unambiguously communicates the overall view of the
system (problem-domain).

02/25/2014 UML 10
More on UML...
Specifying - UML provides the means to
model precisely, unambiguously and completely,
the system in question.

Constructing - models built with UML have a


“design” dimension to it; these are language
independent and can be implemented in any
programming language.

02/25/2014 UML 11
More on UML...
Documenting - every software
project involves a lot of documentation -
from the inception phase to the
deliverables.

UML provides the


notations for documenting
Documentation is some of these artifacts
(among others) for:

• Requirements
• Design
• Tests
02/25/2014 UML 12
What is UML and Why we use UML?
Year Version
2003: UML 2.0
2001: UML 1.4
1999: UML 1.3
1997: UML 1.0, 1.1
1996: UML 0.9 & 0.91
1995: Unified Method 0.8

Booch „93 OMT - 2


Other methods

Booch „91
OMT - 1

02/25/2014 UML 13
How to use UML diagrams to
design software system?
 Types of UML Diagrams:
 Use Case Diagram
 Class Diagram
 Sequence Diagram
 Collaboration Diagram
 State Diagram

This is only a subset of diagrams … but are most widely used

02/25/2014 UML 14
Use-Case Diagrams
 A use-case diagram is a set of use cases
 A use case is a model of the interaction between
 External users of a software product (actors) and
 The software product itself
 More precisely, an actor is a user playing a specific role

 describing a set of user scenarios


 capturing user requirements
 contract between end user and software developers

02/25/2014 UML 15
Use-Case Diagrams
Boundary Use Case
Actor Library System

Borrow Employee
Client

Order Title

Fine Remittance

Supervisor

02/25/2014 UML 16
Use-Case Diagrams
 Actors: A role that a user plays with respect to the system, including human
users and other systems. e.g., inanimate physical objects (e.g. robot); an
external system that needs some information from the current system.

 Use case: A set of scenarios that describing an interaction between a user


and a system, including alternatives.

 System boundary: rectangle diagram representing the boundary between


the actors and the system.

02/25/2014 UML 17
Use-Case Diagrams
 Association:
communication between an actor and a use case; Represented by a solid line.

 Generalization: relationship between one general use case and a special use
case (used for defining special alternatives) Represented by a line with a
triangular arrow head toward the parent use case.

02/25/2014 UML 18
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” in stead of copying the description of that behavior.
<<include>>

Extend: a dotted line labeled <<extend>> with an arrow toward


the base case. The extending use case may add behavior to the
base use case. The base class declares “extension points”.

<<extend>>

02/25/2014 UML 19
Use-Case Diagrams

Figure 16.12
02/25/2014 UML
The McGraw-Hill Companies, 2005 20
Use-Case Diagrams
 Both Make Appointment
and Request Medication
include Check Patient
Record as a subtask
(include)

 The extension point is


written inside the base
case Pay bill; the
extending class Defer
payment adds the
behavior of this extension
point. (extend)

 Pay Bill is a parent use


case and Bill Insurance
is the child use case.
(generalization)

(TogetherSoft, Inc)

02/25/2014 UML 21
Class diagram
 A class diagram depicts classes and their interrelationships

 Used for describing structure and behavior in the use cases

 Provide a conceptual model of the system in terms of


entities and their relationships

 Used for requirement capture, end-user interaction

 Detailed class diagrams are used for developers

02/25/2014 UML 22
Class diagram
 Each class is represented by a rectangle subdivided into three
compartments
 Name
 Attributes
 Operations

 Modifiers are used to indicate visibility of attributes and


operations.
 „+‟ is used to denote Public visibility (everyone)
 „#‟ is used to denote Protected visibility (friends and derived)
 „-‟ is used to denote Private visibility (no one)

 By default, attributes are hidden and operations are visible.

02/25/2014 UML 23
Class diagram
Name
Account_Name
- Customer_Name
Attributes
- Balance
+addFunds( ) Operations
+withDraw( )
+transfer( )

02/25/2014 UML 24
OO Relationships

 There are two kinds of Relationships


 Generalization (parent-child relationship)
 Association (student enrolls in course)

 Associations can be further classified as


 Aggregation
 Composition

02/25/2014 UML 25
OO Relationships: Generalization

Supertype Example: Customer

Regular Loyalty
Customer Customer

Subtype1 Subtype2
-Inheritance is a required feature of object orientation
-Generalization expresses a parent/child relationship among related classes.
-Used for abstracting details in several layers

02/25/2014 UML 26
OO Relationships: Association

 Represent relationship between instances of classes


 Student enrolls in a course
 Courses have students
 Courses have exams
 Etc.

 Association has two ends


 Role names (e.g. enrolls)
 Multiplicity (e.g. One course can have many students)
 Navigability (unidirectional, bidirectional)

02/25/2014 UML 27
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.”

02/25/2014 UML 28
Class diagram

02/25/2014 [from UML Distilled UML


Third Edition] 29
Association: Model to Implementation

* 4
Student Course
has enrolls

Class Student {
Course enrolls[4];
}

Class Course {
Student have[];
}

02/25/2014 UML 30
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
[From Dr.David A. Workman]
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
02/25/2014
The McGraw-Hill Companies, 2005 UML 31
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.

Class E1 Class E2 express a more informal relationship than


composition expresses.

Containee Classes Aggregation is appropriate when Container and


Containees have no special access privileges to
each other.
Example
Bag

Apples Milk

02/25/2014 UML 32
[From Dr.David A. Workman]
Aggregation vs. Composition
Composition is really a strong form of association
components have only one owner
components cannot exist independent of their owner
components live or die with their owner
e.g. Each car has an engine that can not be shared with other cars.

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.

02/25/2014 UML 33
Good Practice: CRC Card
Class Responsibility Collaborator
 easy to describe how classes work by moving cards around; allows to
quickly consider alternatives.

02/25/2014 UML 34
Interaction Diagrams
 show how objects interact with one another

 UML supports two types of interaction


diagrams
 Sequence diagrams
 Collaboration diagrams

02/25/2014 UML 35
Sequence Diagram(make a phone call)
Caller Phone Recipient

Picks up

Dial tone

Dial

Ring notification Ring

Picks up

Hello

02/25/2014 UML 36
Sequence Diagram:Object interaction
A B
Self-Call: A message that an
Synchronous
Object sends to itself.

Condition: indicates when a Asynchronous


message is sent. The message is
Transmission
sent only if the condition is true. delayed

[condition] remove()
Condition
*[for each] remove()
Iteration

Self-Call
02/25/2014 UML 37
Sequence Diagrams – Object Life Spans
 Creation
A
 Create message

 Object life starts at that point


Create
 Activation B
 Symbolized by rectangular stripes

 Place on the lifeline where object

is activated.
 Rectangle also denotes when

object is deactivated.
 Deletion Activation bar
X
Return
 Placing an „X‟ on lifeline
Deletion
 Object‟s life ends at that point Lifeline

02/25/2014 UML 38
Sequence Diagram
User Message Catalog Reservations

•Sequence diagrams demonstrate


the behavior of objects in a use case 1: look up ()

by describing the objects and the 2: title data ()


messages they pass.
3: [not available] reserve title ()

4 : title returned ()
•The horizontal dimension shows the
objects participating in the interaction. 5: hold title ()

5 : title available ()

•The vertical arrangement of 6 : borrow title ()


messages indicates their order.
6 : remove reservation ()

•The labels may contain the seq. # to


indicate concurrency.
02/25/2014 UML 39
Interaction Diagrams: Collaboration diagrams

start

6: remove reservation

3 : [not available] reserve title


User Reservations

6 : borrow title 5: title available

1: look up
2: title data

4 : title returned
Catalog

5 : hold title

Collaboration diagrams are equivalent to sequence diagrams. All the features of sequence
diagrams are equally applicable to collaboration diagrams
Use a sequence diagram when the transfer of information is the focus of attention
Use a collaboration diagram when concentrating on the classes
02/25/2014 UML 40
State Diagrams (Billing Example)

State Diagrams show the sequences of states an object goes through


during its life cycle in response to stimuli, together with its responses and
actions; an abstraction of all possible behaviors.

Start End
Unpaid Paid
Invoice created paying Invoice destroying

02/25/2014 UML 41
State Diagrams (Traffic light example)

Traffic Light Start


State
Transition Red

Yellow

Green

Event

02/25/2014 UML 42
What UML Modeling tools we use today?
 List of UML tools http://en.wikipedia.org/wiki/List_of_UML_tools

 ArgoUML: http://argouml.tigris.org/

 Rational Rose (www.rational.com) by IBM

 UML Studio 7.1 ( http://www.pragsoft.com/) by Pragsoft Corporation:


Capable of handling very large models (tens of thousands of classes).
Educational License US$ 125.00; Freeware version.

 TogetherSoft Control Center; TogetherSoft Solo


(http://www.borland.com/together/index.html) by Borland

02/25/2014 UML 43
Design using UML
 Many OOAD methodologies have been proposed
 They provide some guidelines on the steps to be
performed
 Basic goal is to identify classes, understand their
behavior, and relationships
 Different UML models are used for this
 Often UML is used, methodologies are not
followed strictly

02/25/2014 UML 44
Design using UML
 Basic steps
 Identify classes, attributes, and operations from use
cases
 Define relationships between classes
 Make dynamic models for key use cases and use them
to refine class diagrams
 Make a functional model and use it to refine the
classes
 Optimize and package
 Class diagrams play the central role; class
definition gets refined as we proceed

02/25/2014 UML 45
Success Scenario
 Customer read the menu
 Customer places the order
 Order is sent to the kitchen for preparation
 Ordered items are served
 Customer requests for a bill for the order
 Bill is prepared for this order
 Customer is given the bill
 Customer pays the bill

02/25/2014 UML 46
Restaurant example: Initial classes

02/25/2014 UML 47
02/25/2014 UML 48
Restaurant example: a sequence diagram

02/25/2014 UML 49
Example: Word Count Problem
 System prompts for the file name; user
enters the file name
 System checks for existence of file
 System reads the words from the file
 Systems prints the count

02/25/2014 UML 50
Example: Word Count Problem…
File

name

History getword()
isEof() Counter
addWord() count

exists() increment()
display()

Word

string
setstring()
getstring()

02/25/2014 UML 51
Example: Word Count Problem…

Check
Read Get
For
File words
Uniqueness

Increment Add to
Count History

02/25/2014 UML 52
Conclusion
 UML is a standardized specification language
for object modeling
 Several UML diagrams:
 use-case diagram: a number of use cases (use case models the interaction
between actors and software)
 Class diagram: a model of classes showing the static relationships among them
including association and generalization.
 Sequence diagram: shows the way objects interact with one another as
messages are passed between them. Dynamic model
 State diagram: shows states, events that cause transitions between states.
Another dynamic model reflecting the behavior of objects and how they react to
specific event

 There are several UML tools available

02/25/2014 UML 53
END

02/25/2014 UML 54

You might also like