Sei sulla pagina 1di 69

Chapter 3

Modeling with Unified


Modeling Language
A Deeper View of UML

UML Diagrams:
Outline of this Class


Use case diagrams


 Describe the functional behavior of the system as seen by the
user
Interaction diagrams
 Describe the dynamic behavior between objects of the system
Activity diagrams
 Describe the dynamic behavior of a system, in particular the
workflow.
Class diagrams
 Describe the static structure of the system: Objects, attributes,
associations
Statechart /State Machine diagrams
 Describe the dynamic behavior of an individual object

Activity Diagram

describe the workflow behavior of a system.


 describe the state of activities by showing the
sequence of activities performed.
 show activities that are conditional or
parallel.
 focuses on flows driven by internal
processing


 Focus on flow of activity of internal process


in object
 similar to flowchart
 describe changes in activity in a procedure
 information from use case scenario or
event flow can be used to describe activity
diagram.
 Used to provide detail for complex
algorithms
5

Notation of Activity
Diagrams


Actions
rectangle with rounded corners
 meaningful name


Control flows


Add a New
Client

Assign Staff
Contact

arrows with open


arrowheads

Notation of Activity
Diagrams


Initial node


diamond

Guard conditions


black circle

Decision nodes
(and merge nodes)


in square brackets

Final node


Add a New
Client

Assign Staff
Contact
[no campaign to add]
[campaign to add]
Add New
Campaign

black circle in white circle

Notation of Activity
Diagrams


Fork nodes
and join nodes


Add a New
Client

thick bar

Actions carried
out in parallel

Add New
Campaign

Assign Staff
Contact

Notation of Activity
Diagrams

:Campaign
[Active]

Object flows


open arrow

Record completion
of a campaign

Objects
rectangle
 optionally shows
the state of the
object in square
brackets


:Campaign
[Completed]

Notation of Activity
Diagrams
Campaign
Manager

Activity Partitions
(Swimlanes)
vertical columns
 labelled with the
person, organisation,
department or
system responsible
for the activities in
that column

Accountant

Client

Record Completion
of a campaign

Issue invoice

Pay invoice

Record client
payment

10

The main reason to use activity diagrams is


to model the workflow behind the system
being designed.
 Activity Diagrams are also useful for:


analyzing a use case by describing what actions need


to take place and when they should occur;
describing a complicated sequential algorithm;

modeling applications with parallel processes.

11

Example of Activity Diagram for ATM Authorization

Enter card

Enter PIN

Read card

Request PIN
[No]

Verify PIN

valid?
[Yes]

Select other
service

12

Swimlane
- partition an
activity diagram so
that parts in the
swimlane relevant
to that activities in
the partition
- helpful in
investigating
responsibilities for
interactions and
associations
between objects
and actors

13

Activity diagram with


synchronization bars
split into multiple
paths and multiple
paths combined into
a single transition
Top synchronization
bar is a fork.
Bottom
synchronization bar
is a join.

14

15

Model interactions between objects/classes


 Assist in understanding how a use case
actually works
 Verify that a use case description can be
supported by the existing classes
 Identify methods/operations and assign them
to classes


16

State Diagrams

Statechart Diagrams





used to describe the dynamic behavior of an


individual object as a number of states and
transitions between these states.
describe all of the possible states of an object
as events occur.
each diagram usually represents objects of a
single class and track the different states of its
objects through the system

Initial state

Event
button1&2Pressed

Blink
Hours

button2Pressed

Increment
Hours

button1Pressed

Transition
button1&2Pressed

State

Blink
Minutes

button2Pressed

Increment
Minutes

button1Pressed

Blink
Seconds

Stop
Blinking

button2Pressed

Final state

Represents behavior of a single object with


interesting dynamic behavior.

Increment
Seconds

When to use State


Diagram?
Use state diagrams to demonstrate the
behavior of an object through many use
cases of the system.
 Only use state diagrams for classes where it
is necessary to understand the behavior of
the object through the entire system


Modeling Structure
Class Diagram

21

Classes are composed of three things: a


name, attributes, and operations

22

Show the static structure of the model

A collection of static modeling elements, such as


classes and their relationships, connected to each other

Logical objects in the real world (problem domain) are


represented by the actual objects in the program

The visual representation of the objects, their


relationships, and their structure for ease of
understanding

What you need? determine the objects required in the


system
23

Class Diagram: Associations


Associations represent:
 The possibility of a logical relationship or
connection between objects of one class
and objects of another



Grace Chia is the staff contact for FoodCo


An employee object is linked to a client
object

If two objects are linked, their classes are


said to have an association

24

Class Diagram: Links


Yellow Partridge:Client

A link is a logical connection


between two objects
FoodCo:Client

Soong Motor Co:Client

Grace Chia:StaffMember

Carlos Moncada:StaffMember

25

Class Diagram: Associations


Association role

Association
Client

StaffMember
staffName

companyAddress

staffContact

staffNo
staffStartDate

companyEmail
liaises with

companyFax
companyName
companyTelephone

Association name

Direction in which
name should be read
26

Class Diagram: Multiplicity


Associations have multiplicity: the range of
permitted cardinalities of an association
 Represent enterprise (or business) rules
 These always come in pairs:


Associations must be read separately from


both ends
 Each bank customer may have 1 or more
accounts
 Every account is for 1, and only 1, customer


27

Class Diagram: Multiplicity


Multiplicities
StaffMember
staffName
staffNo
staffStartDate

Client
companyAddress
0..* companyEmail

1
liaises with

companyFax
companyName
companyTelephone

Exactly one staff member liaises with each client


A staff member may liaise with zero, one or more clients
28

Classes are organize into a subclasssuperclass hierarchy


 The top of the class hierarchy are the most
general classes and at the bottom are the
most specific
 Subclass inherits all the properties and
methods defined in its superclass
 Subclass can add new properties and
methods specific to itself


29

Motor Vehicle

Bus

Truck

Car

30

A relationship between classes where one


class is parent class(superclass) of another
class
 Allows objects to be built from other objects
 Allows classes to share and reuse behaviors
and attributes


31

class Person {
String Name;
}
class Employee extends Person
{}
class Client extends Person {}

32

Objects are composed of and may contain


other objects
 E.g, car object is an aggregation of other
objects such as engine, seat, and wheel
objects.


Car

Engine

Seat

Wheel

33

has

34

Class diagrams are used in nearly all Object


Oriented software designs.
 Use them to describe the Classes of the
system and their relationships to each other
 Show relationship of all classes and object
as an overall picture


35

Example : Class Diagram


Object /Class

Association

Generalization
Library Item

User

Borrows

No. Copies
ShelfNo
Status
Title
Issue
Return
Shelve

0..*

Address
Member#
Name
Subscribe
Unsubscribe

External Reader
Ext. Library Name

Recorded Media

Borrower
Items Borrowed
Maximum Loans

Aggregation

Book
Author
ISBN
Pub. Date
Publisher

CAL Package
Distributor
Course Text

Summary Class Relationship


Plan

ASSOCIATION

GENERALIZATIO
N/ INHERITANCE

PlanAnalyst
GrowingPlan

GardeningPlan

1..2
analyzes
1..*
PlanMetrics
FruitGrowingPlan

AGGREGATION/COMPOSITION
Controller

*
Light

Food

Cooler

1..23
1

Vitamin

Calorie

Heater

OOAD
37

Member
Member-Number
Member-Name
Member-Status
Member-Street-Address
Member-PO-Box
Member-City
Member-State
Member-Zip-Code
persistent

<<actor>>
Potential Member

<<actor>>
Club Member

persistent

Has
purchased
0..*
Member Ordered Product

Product
Product-Number
UPCQuantity-In-Stock
Product-Type
1
Suggested-Retail-Price
Default-Unit-Price
Current-Special-Unit-Price
Current-Month-Units-Sold
Current-Year-Units-Sold
Total-Lifetime-Units-Sold

Quantity-Ordered
Quantity-Shipped
Quantity-Backordered
Purchase-Unit-Price
Credits-Earned

Sold as

<<actor>>
Past Member

Member-Date-Of-Last-Order
Member-Daytime-Phone-Number
Member-Credit-Card-Expire-Date
Member-Credit-Card-Number
Member-Credit-Card-Type
Member-Balance-Due
Member-Bonus-Balance-Available
1..*
Audio-Category-Preference
Audio-Media-Preference
Date-Enrolled
Email-Address
Game-Category-Preference
Game-Media-Preference
Number-Of-Credits-Earned
Privacy-Code
Video-Category-Preference
Video-Media-Preference
1
persistent

0..*

Expiration-Date

binds

persistent

Transaction
Conduct
s

Transaction-Reference-Number
Transaction-Date
Transaction-Type
Transaction-Description
Transation-Amount
persistent

1..*
Places

0..*
Member Order

Sells
Merchandise

Title

Merchandise-Name
Merchandise-Description
Merchandise-Type
Unit-of-Measure

Title-Of-Work
Title-Cover
1..*
Catalog-Description
Copyright-Date
Feature
Entertainment-Company
s
Credit-Value
persistent

1
Promotion

0..*

Promotion-Number
Promotion-Release-Date
0..1
Promotion-Status
Promotion-Type
persistent

Generate
s
0..*

Order-Number
Order-Creation-Date
Order-Fill-Date
Shipping-Address-Name
Shipping-Street-Address
Shipping-City
Shipping-State
Shipping-Zip-Code
Shipping-Instructions
Order-Sub-Total
Order-Sales-Tax
Order-Shipping-Method
Order-Shipping-&-Handling-Cost
Order-Status
Order-Prepaid-Amount
Order-Prepayment-Method
persistent

Audio Tilte

Video Title

Game Title

Artist
Audio-Category
Audio-Sub-Category
Number-Of-Units-In-Package
Audio-Media-Code
Content-Advisory-Code

Producer
Director
Video-Category
Video-Sub-Category
Closed-Captioned
Language
Running-Time
Video-Media-Type
Video-Encoding
Screen-Aspect
MPA-Rating-Code

Manufacturer
Game-Category
Game-Sub-Category
Game-Platform
Game-Media-Type
Number-Of-Players
Parent-Advisory-Code

persistent

persistent

persistent

Agreement-Number
Agreement-Expire-Date
Agreement-Active-Date
Fulfillment-Period
Required-Number-Of-Credits

persistent

0..*
persistent

Agreement

persistent

persistent

Return

persistent

How to Construct
Class Diagram
Steps:
Identify object classes
Identify associations
Identify object attributes
Organize object classes using
inheritance
Describe communication using
sequence diagrams or use case
narratives
Group classes
39

:Order Entry
:Order
window
prepare()

:Order Line

:Stock Item

:Reorder
Item

:Delivery
Item

prepare()
check()
truremove()
needsToReorder()
[needsToReorder=true]
enter new

[check=true]
enter new
40

Order

OrderLine

orderNumber
date
etc

itemnumber
quantity
etc

prepare()

prepare()

ReOrderItem
itemnumber
quantity
etc
enter new()

StockItem
orderNumber
minQuantity
date
etc
needsToReorder():
boolean

DeliveryItem
is_for

deliveryadress
quantity
etc
enter new()

check(): boolean
remove()

41

Class Diagram

42

The requirements list of a company includes the


following description of the use case make an
order

Customer

make an order

We have customers who make an order


We distinguish corporate customers from personal customers, since corporate
customers are billed monthly whereas personal customers need to prepay their orders
with a credit card
We want our orders to be lined up product by product
Each line should contain the amount and the price of each product
43

Order

Customer
*

make

We have customers who make an order


We distinguish corporate customers from personal customers, since corporate
customers are billed monthly whereas personal customers need to prepay their orders
with a credit card
We want our orders to be lined up product by product. Each line should contain the
amount and the price of each product

44

Order

Customer
*

make

Corporate

Personal

We have customers who make an order


We distinguish corporate customers from personal customers, since corporate
customers are billed monthly whereas personal customers need to prepay their
orders with a credit card
We want our orders to be lined up product by product. Each line should contain the
amount and the price of each product
45

Order

Customer
*

make

1
*
OrderLine

Product
*

Corporate

Personal

We have customers who make an order


We distinguish corporate customers from personal customers, since corporate
customers are billed monthly whereas personal customers need to prepay their orders
with a credit card
We want our orders to be lined up product by product. Each line should contain
the amount and the price of each product
46

Order
orderID:char
Price:money

Customer
*

make

name:char
address:char

1
*
OrderLine
Amount:Integer
Price:money

Product

Corporate

Personal
CreditcardNo:char

billMonthly(int)

We have customers who make an order


We distinguish corporate customers from personal customers, since corporate
customers are billed monthly whereas personal customers need to prepay their orders
with a credit card
We want our orders to be lined up product by product. Each line should contain the
amount and the price of each product
47

Summary: UML Diagrams

Other Diagrams

49

OOAD

Component Diagram displays the high level packaged


structure of the code itself. Dependencies among
components are shown, including source code
components, binary code components, and executable
components.
Deployment Diagram displays the configuration of runtime processing elements and the software
components, processes, and objects that live on
them. Software component instances represent runtime manifestations of code units
Package Diagram shows how model elements are
organized into packages as well as the dependencies
between packages
50

Model the physical components (e.g., source


code, program, user interface) in a design
 Addresses the static implementation view of
a system
 Built as part of architectural specification
 Purpose


Organize source code


 Construct an executable release
 Specify a physical database


Developed by architects and programmers


51

Notation of
Component Diagrams


Components



rectangles with a component icon


right-hand corner
may provide or require interfaces

in the top

Dependencies between components


Production
scheduler

Staff planner
52

Notation of
Component Diagrams


Wiring connection (ball-and-socket


connectors) between required and provided
interfaces
Required interface

Scheduling

Provided interface

Production
scheduler

Staff planner
Planning

Production scheduler requires the Planning service


from Staff planner. Staff planner provides the
Planning service
53

Notation of
Component Diagrams


Component with ports




Indicates that the component delegates


responsibility for the behaviour of that
interface to a subcomponent
Spooler
Spooling

PrinterDriver

port
54

Notation of
Component Diagrams


Component with ports




Shows delegated responsibility


Spooler
delegate

delegate

Spooling
:PrintManager
Print
Spooling

PrinterDriver
Printing

:File

55

Components
Components have changed in UML 2.0
 They are no longer shown in Deployment
Diagrams, where they have been replaced
by Artefacts
 Components are specifically modular
software units with well-defined interfaces
 They can be logical or physical


56

57







Captures the topology of a systems hardware


Show the configuration of run-time processing
elements and the s/w components, processes,
and objects that live in them
Built as part of architectural specification
Purpose
 Specify the distribution of components
 Identify performance bottlenecks
Developed by architects, networking engineers,
and system engineers
58

Notation of
Deployment Diagrams


Nodes
rectangular prisms
 represent processors, devices or other
resources


Communication Associations
lines between nodes
 represent communication between nodes
 can be stereotyped


59

Notation of
Deployment Diagrams

TCP/IP
swift:PC

node

aardvark:DECAlpha

Communication association

60

Notation of
Deployment Diagrams


Can be shown with


artefacts located on the
nodes
Artefacts are related to
components by a
manifest relationship

Agate Client

manifest

AgateClient.jar

61

Notation of
Deployment Diagrams

PC Client

AgateClient.jar

Server

RMI

AgateServer.jar

62

Notation of
Deployment Diagrams



Nodes can be stereotyped


A device is a kind of
composite node that consists
of other devices or nodes
Execution environments
represent application
containers
Deployment specifications
describe the configuration of
artefacts

device
:AppServer
executionenv
:J2EEContainer
AgateServer.war

deploymentspec
serverconfig.xml

63

64

Another way of looking at components


 A package is a grouping of model elements
(e.g., group of classes)
 Packages themselves may contain other
packages
 A package may contain both subordinate
package and ordinary model elements
 All UML model elements and diagrams can
be organized into packages


65

dependency

66

Summary
A deeper view of UML
Use case diagram
 Sequence Diagram
 Activity Diagram
 Statechart Diagram
 Class Diagram
 Physical Diagrams


67

Architecture and the UML

Implementation
View

Design View

Use Case
View
Process View

logical

Deployment View

physical

Additional Readings
The Elements of UML 2.0 Style, Scott W.
Ambler, Ronin International, 2005
 The Object Primer 3rd Edition, Scott W.
Ambler, Cambridge University Press, 2004
 UML Distilled: A Brief Guide to the Standard
Object Modeling Language (3rd Edition),
Martin Fowler, Addison-Wesley
Professional, 2004


Potrebbero piacerti anche