Escolar Documentos
Profissional Documentos
Cultura Documentos
UsingUML,Patterns,andJava
Part 2
Chapter 2,
Modeling with UML,
Outline of this Class
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
What is UML? Unified Modeling
Language
Convergence of different notations used in object-
oriented methods, mainly
OMT (James Rumbaugh and collegues), OOSE (Ivar
Jacobson), Booch (Grady Booch)
They also developed the Rational Unified Process,
which became the Unified Process in 1999
Developedthe
Boochmethod
25yearatGEResearch, AtEricssonuntil1994, (clouds),ACM
wherehedevelopedOMT, developedusecasesandthe Fellow1995,and
joined(IBM)Rationalin CASEtoolObjectory,atIBM IBMFellow2003
1994,CASEtoolOMTool Rationalsince1995, http://www.booch.
http://www.ivarjacobson.com com/
UML
Nonproprietary standard for modeling systems
Current Version: UML 2.2
Information at the OMG portal http://www.uml.org/
Commercial tools:
Rational (IBM),Together (Borland), Visual Architect (Visual
Paradigm), Enterprise Architect (Sparx Systems)
Open Source tools http://www.sourceforge.net/
ArgoUML, StarUML, Umbrello (for KDE), PoseidonUML
Example of research tools: Unicase, Sysiphus
Based on a unified project model for modeling,
collaboration and project organization
http://unicase.org
http://sysiphus.in.tum.de/
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
UML: First Pass
VilfredoPareto,18481923
IntroducedtheconceptofPareto
Efficiency,
Founderofthefieldofmicroeconomics.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
UML First Pass (covered in Last
Lecture)
Use case diagrams
Describe the functional behavior of the system as seen by
the user
Class diagrams
Describe the static structure of the system: Objects,
attributes, associations
Sequence diagrams
Describe the dynamic behavior between objects of the
system
Statechart diagrams
Describe the dynamic behavior of an individual object
Activity diagrams
Describe the dynamic behavior of a system, in particular
the workflow.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
UML Basic Notation: First Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
UML Use Case Diagrams
Used during requirements elicitation
and analysis to represent external
behavior (visible from the outside of
the system)
An Actor represents a role, that
is, a type of user of the system
Passenger
A use case represents a class of
functionality provided by the system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Actors
An actor is a model for an external
entity which interacts
(communicates) with the system:
User
External system (Another system)
Physical environment (e.g. Weather)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Use Case
A use case represents a class of
functionality provided by the system
Use cases can be described textually,
with a focus on the event flow
between actor and system
The textual use case description
consists of 6 parts:
1. Unique name
PurchaseTicket
2. Participating actors
3. Entry conditions
4. Exit conditions
5. Flow of events
6. Special requirements.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Textual Use Case
Description Example PurchaseTicket
Passenger
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Uses Cases can be related
Extends Relationship
To represent seldom invoked use cases or exceptional
functionality
Includes Relationship
To represent functional behavior common to more than
one use case.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
The <<extends>> Relationship
<<extends>> relationships
model exceptional or seldom
invoked cases
The exceptional event flows
Passenger are factored out of the main
event flow for clarity
The direction of an
<<extends>> relationship is to
PurchaseTicket the extended use case
Use cases representing
<<extends>> exceptional flows can extend
more than one use case.
<<extends>>
<<extends>>
OutOfOrder <<extends>> TimeOut
Cancel NoChange
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
The <<includes>>Relationship
<<includes>> relationship
represents common
functionality needed in more
Passenger
than one use case
<<includes>> behavior is
factored out for reuse, not
PurchaseMultiCard because it is an exception
PurchaseSingleTicket The direction of a
<<includes>>
<<includes>> relationship is
to the using use case (unlike
<<includes>>
the direction of the
<<extends>> relationship).
CollectMoney
<<extends>> <<extends>>
<<extends>>
TarifSchedule Trip
Tablezone2price
zone:Zone
EnumerationgetZones()
* * Price:Price
PricegetPrice(Zone)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
Classes Type
TarifSchedule
Tablezone2price
EnumerationgetZones()
Name PricegetPrice(Zone)
TarifSchedule
zone2price Attributes Signature
getZones()
getPrice()
Operations TarifSchedule
tarif2006:TarifSchedule :TarifSchedule
zone2price={ zone2price={
{1,0.20}, {1,0.20},
{2,0.40}, {2,0.40},
{3,0.60}} {3,0.60}}
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
Actor vs Class vs Object
Actor
An entity outside the system to be modeled,
interacting with the system (Passenger)
Class
An abstraction modeling an entity in the application or
solution domain
The class is part of the system model (User, Ticket
distributor, Server)
Object
A specific instance of a class (Joe, the passenger who
is purchasing a ticket from the ticket distributor).
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
Associations
TarifSchedule TripLeg
Price
EnumerationgetZones()
* * Zone
PricegetPrice(Zone)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
1-to-1 and 1-to-many Associations
Country 1 1 City
name:String name:String
1to1association
Point
Polygon
* x: Integer
y: Integer
draw()
1tomanyassociation
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
Many-to-Many Associations
Company
StockExchange * * tickerSymbol
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
From Problem Statement To Object
Model
ProblemStatement:Astockexchangelistsmanycompanies.
Eachcompanyisuniquelyidentifiedbyatickersymbol
Class Diagram:
StockExchange * * Company
Lists
tickerSymbol
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
From Problem Statement to Code
ProblemStatement :Astockexchangelistsmanycompanies.
Eachcompanyisidentifiedbyatickersymbol
Class Diagram:
StockExchange * * Company
Lists tickerSymbol
Java Code
publicclassStockExchange
{
privateVectorm_Company=newVector();
};
Associations
are mapped to
publicclassCompany
{ Attributes!
publicintm_tickerSymbol;
privateVectorm_StockExchange=newVector();
};
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
Aggregation
An aggregation is a special case of association denoting
a consists-of hierarchy
Exhaust system
The aggregate is the parent class,
the components are the children classes
1 0..2
Muffler Tailpipe
diameter diameter
3
ZoneButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Qualifiers
Without qualification
1 * File
Directory
filename
With qualification
1 0..1
Directory filename File
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25
Qualification: Another Example
Company
StockExchange * Lists
* tickerSymbol
StockExchange
*
tickerSymbol
Lists
*
1 Company
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26
Inheritance
Button
CancelButton ZoneButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
Packages
Packages help you to organize UML models to increase
their readability
We can use the UML package mechanism to organize
classes into subsystems
Account
Bank Customer
Any complex system can be decomposed into subsystems,
where each subsystem is modeled as a package.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
Object Modeling in Practice
Foo
Amount
CustomerId
Deposit()
Withdraw()
GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29
Object Modeling in Practice:
Brainstorming
Dada Foo
Amount Amount
CustomerId CustomerId
Deposit() Deposit()
Withdraw() Withdraw()
GetBalance() GetBalance()
Account
Amount
CustomerId
Deposit()
Withdraw()
Is Foo the right name? GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30
Object Modeling in Practice: More
classes
Account
Amount Customer
Bank AccountId
CustomerId
Name
Name Deposit() CustomerId
Withdraw()
GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
Object Modeling in Practice:
Associations
Account
? * Amount
* owns
Customer
Bank has AccountId
CustomerId
AccountId
Name
Deposit() 2
Name CustomerId
Withdraw()
GetBalance()
Name
* Amount
* Has Name
AccountId
CustomerId
AccountId
Deposit()
Withdraw()
GetBalance() CustomerId()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33
Practice Object Modeling: Simplify,
Organize
Account
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34
Practice Object Modeling: Simplify,
Organize
Account
Bank Customer
Name
* Amount
* Has Name
AccountId
CustomerId
AccountId
Deposit()
Withdraw()
GetBalance() CustomerId()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
Sequence Diagrams Focus on
Controlflow
selectZone()
lookupPrice(selection)
price
displayPrice(price)
Dataflow
continued on next slide...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37
Sequence Diagrams: Iteration &
Condition
continued from previous slide...
*insertChange(coin) lookupCoin(coin)
price
Iteration displayPrice(owedAmount)
[owedAmount<0]returnChange(owedAmount)
Condition
continued on next slide...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38
Creation and destruction
continued from previous slide...
Creation of Ticket
ChangeProcessor
Passenger
createTicket(selection)
Ticket
print()
free()
Destruction of Ticket
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39
Sequence Diagram Properties
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40
Outline of this Class
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41
Activity Diagrams
An activity diagram is a special case of a state
chart diagram
The states are activities (functions)
An activity diagram is useful to depict the
workflow in a system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42
Activity Diagrams allow to model
Decisions
Decision
[lowPriority]
Open Allocate
Incident Resources
[fire&highPriority]
[notfire&highPriority]
Notify
FireChief
Notify
PoliceChief
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43
Activity Diagrams can model
Concurrency
Synchronization of multiple activities
Splitting the flow of control into multiple threads
Allocate
Splitting Resources Synchronization
Document
Incident
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44
Activity Diagrams: Grouping of
Activities
Activities may be grouped into swimlanes to
denote the object or subsystem that implements
the activities.
Allocate Dispatcher
Resources
FieldOfficer
Document
Incident
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45
Activity Diagram vs. Statechart
Diagram
Statechart Diagram for Incident
Focus on the set of attributes of a single abstraction (object, system)
Event causes
state transition
Triggerless
Completion of activity transition
causes state transition
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46
UML Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47