Lecture for Chapter 2 Modeling with UML
Document Sample


Modelling
with UML
CS223 Lecture 4 (see BD Ch. 2) Ananda Amatya
Notice: Surgery Sessions (Weeks 6-10)
Mon 2 - 4 in C1.01 & Fri 9 - 11 in C1.04
Please attend any one session convenient to you
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 1
Overview: modelling with UML
What is modelling? What is UML? Use case diagrams Class diagrams Sequence diagrams (Collaboration diagrams) Activity diagrams StateChart diagrams
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
2
What is modelling?
Modelling building an abstraction of reality. Abstractions simplifications: ignore irrelevant details focus on matters of concern. What is relevant and what is irrelevant? depends on the purpose of the model.
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
3
Example: street map that models access roads
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
4
Why model software?
More sophisticated software means more complexity: Windows XP > 40 million lines of code;
Several coders must be involved. One developer’s code must be understood by another developer. Complex systems must be simplified: Modelling is a way of achieving this.
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
5
Systems, Models and Views
System: an organised set of communicating parts. Model: an abstraction describing a subset of a system. View: a selected aspect of a model. Notation: a set of graphical or textual rules for depicting views. Views and models of a single system may overlap each other.
Examples: System: Aircraft Models: Flight simulator, scale model Views: All blueprints, electrical wiring, fuel system
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 6
Bernd Bruegge & Allen H. Dutoit
Systems, Models and Views
Aircraft
Blueprints
Model
Flightsimulator
2 View View 3 2
System
View
1
Model
1
Fuel System Scale Model Electrical Wiring
7
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Models, Views and Systems (UML)
System
*
Model
*
View
Described by
Depicted by
Airplane: System
Scale Model: Model
Flight Simulator: Model
Blueprints: View
Bernd Bruegge & Allen H. Dutoit
Fuel System: View
Electrical Wiring: View
8
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Concepts and Phenomena
Phenomenon: An object in the world of a domain as you perceive it. Examples: this lecture, that wall clock Concept: An abstraction that describes phenomena with common properties. Examples: Lecture, Wall clock Concept is a 3-tuple: Name (to distinguish one concept from another) Purpose (to determine if a phenomenon belongs to a concept) Members (the set of phenomena that belong to the concept - instances)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 9
Concepts and Phenomena (contd.)
Name Purpose Members
Clock
A device that measures time.
Abstraction Classification of phenomena into concepts Modelling Development of abstractions to answer specific questions about a set of phenomena while ignoring irrelevant details.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 10
Concepts in software: Type and Instance
Type: An abstraction in the context of programming languages Name: int, Purpose: integral number, Members: 0, -1, 1, 2, -2, . . . Instance: Member of a specific type The type of a variable represents all of its possible instances
Bernd Bruegge & Allen H. Dutoit
The following relationships (<–>) are similar: “type” <–> “instance” “concept” <–> “phenomenon”
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
11
Abstract Data Types & Classes
Abstract data type: Special type whose implementation is hidden from the rest of the system. Class: An abstraction in the context of object-oriented languages Like an abstract data type, a class encapsulates both state (variables) and behaviour (methods) Example Class: Watch Unlike abstract data types, classes can be defined in terms of other classes using inheritance
Bernd Bruegge & Allen H. Dutoit
Watch time date SetDate(d)
CalculatorWatch calculatorState EnterCalcMode() InputNumber(n)
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
12
Application and Solution Domain
Application Domain (Requirements Analysis): The environment in which the system is operating
Solution Domain (System Design, Object Design): The available technologies to build the system
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
13
Object-oriented modelling
Application Domain
Solution Domain
UML Package
TrafficControl
Aircraft TrafficController Airport SummaryDisplay MapDisplay FlightPlanDatabase
FlightPlan
TrafficControl
System Model
Application Domain Model
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
14
What is UML?
UML (Unified modelling Language) A standard for modelling object-oriented software. Resulted from the convergence of notations from: OMT (James Rumbaugh) OOSE (Ivar Jacobson) Booch (Grady Booch) Reference: OMG (Object Management Group) Supported by several CASE tools Rational ROSE (IBM) Poseidon (ArgoUML) TogetherJ (Borland) Rhapsody (ILogix) Eclipse (IBM) …
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
15
UML: First Pass
You can model 80% of most problems by using about 20% UML
We teach you those 20%
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
16
UML First Pass
Use case Diagrams describe a system’s functional behaviour as seen by its user. Class diagrams describe a system’s static structure: Classes, Associations Sequence diagrams describe a system’s dynamic behaviour: actors, objects, messages Statechart diagrams describe the dynamic behaviour of individual objects of the system: states, events, transitions Activity Diagrams model a system’s dynamic behaviour: activities, workflows (flowcharts)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 17
UML first pass: Use case diagrams
Package
Watch
Use case
Actor
ReadTime
WatchUser
SetTime
WatchRepairPerson
ChangeBattery
Use case diagrams represent the system’s functionality from user’s point of view
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 18
UML first pass: Class diagrams
Association Class Multiplicity
1 2 PushButton state push() release() 1 LCDDisplay blinkIdx blinkSeconds() blinkMinutes() blinkHours() stopBlinking() referesh() Watch 1 1 1 2 Battery load 1 Time now
Attribute
Operations
Class diagrams represent the structure of the system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 19
UML first pass: Sequence diagram
Actor
:WatchUser
:Watch blinkHours() blinkMinutes()
Object
:LCDDisplay :Time
pressButton1()
pressButton1()
Message
pressButton2()
incrementMinutes()
refresh()
pressButtons1And2() stopBlinking()
commitNewTime()
Activation
Lifeline
Sequence diagrams represent the behaviour as interactions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 20
UML first pass: Statechart (diagrams) for objects with interesting dynamic behaviour
Event
[button1&2Pressed] BlinkHours
State
Initial state
[button2Pressed]
IncrementHrs
Transition
[button1&2Pressed] BlinkMinutes
[button1Pressed]
[button2Pressed] IncrementMin.
[button1Pressed] [button1&2Pressed] BlinkSeconds
[button2Pressed]
IncrementSec.
StopBlinking
Final state
21
Statecharts represent behaviour as states and transitions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Other UML Notations
UML provide other notations Implementation diagrams Component diagrams (BD Chapter 7) Deployment diagrams (BD Chapter 7) UML includes OCL (Object constraint language) Used in Design (BD Chapter 9)
And then … there is UML 2 (a major revision of UML) For a good introduction see IBM Webcast Recorded Event Feb15 Intro.itm in http://developer.raindance.com/iccdoc
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 22
Bernd Bruegge & Allen H. Dutoit
UML Core Conventions
Rectangles are classes or instances Ovals are functions or use cases Instances are denoted with underlined names Examples: myWatch:SimpleWatch, Joe:Firefighter Types are denoted with non-underlined names Examples: SimpleWatch, Firefighter Diagrams are graphs Nodes are entities Arcs are relationships between entities
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
23
Use Case Diagrams
Used during requirements elicitation to capture a system’s external behaviour An Actor represents a user’s role, that is, the type of a user of the system A Use case represents a sequence of interactions for a type of functionality A use case model is the set of all the use cases for a system and its environment, i.e., a complete description of all the functionalities of the system and its environment
24
Passenger
PurchaseTicket
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Actors
An actor models an external entity which communicates with the system: User External system Physical environment Passenger An actor has a unique name and an optional description. Examples: Passenger: A person using a train GPS satellite: A Provider of GPS coordinates to the system
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
25
Use Case
A use case represents a class of functionality provided by the system as an event flow. A use case consists of: Unique name Participating actors Entry conditions Flow of events Exit conditions Special requirements
PurchaseTicket
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
26
Use Case Diagram: Example
Name: Purchase ticket Participating actor: Passenger Entry condition: Passenger standing in front of ticket distributor. Passenger has sufficient money to purchase ticket. Exit condition: Passenger has ticket. Event flow:
1. Passenger selects the number of zones to be travelled. 2. Distributor displays the
amount due. 3. Passenger inserts money, of at least the amount due. 4. Distributor returns change. 5. Distributor issues ticket.
Anything missing? Exceptional cases!
27
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
The <<extends>> Relationship
Passenger
PurchaseTicket
<<extend>> <<extend>>
<<extend>> relationships represent exceptional or seldom invoked cases. The exceptional event flows are separated from the main event flow for clarity. A use case representing exceptional event flows may extend one or more use cases. The direction of a <<extend>> relationship is to the extended use case
<<extend>>
OutOfOrder
<<extend>>
TimeOut
Cancel
Bernd Bruegge & Allen H. Dutoit
NoChange
28
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
The <<includes>> Relationship
<<include>> relationship represents behaviour that is factored out of the use case. <<include>> behaviour is factored out for reuse, not because it is an exception. PurchaseMultiCard The direction of a <<include>> relationship is to the using use case (unlike <<include>> <<extend>> relationships).
Passenger
PurchaseSingleTicket
<<include>>
<<extend>>
CollectMoney
<<extend>>
NoChange
Bernd Bruegge & Allen H. Dutoit
Cancel
29
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Use Case Diagrams: Summary
Use case diagrams represent external behavior Use case diagrams are useful as an index into the use cases Use case descriptions (flow of events) provide meat of model, not the use case diagrams. All use cases need to be described (flow of events) for the model to be useful.
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
30
Class Diagrams
TarifSchedule Enumeration getZones() Price getPrice(Zone)
*
*
Trip zone:Zone Price: Price
Class diagrams represent the structure of the system. Used during requirements analysis to model problem domain concepts during system design to model subsystems and interfaces during object design to model classes.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 31
Classes
TarifSchedule Table zone2price Enumeration getZones() Price getPrice(Zone)
Name
TarifSchedule zone2price getZones() getPrice()
Attributes
Operations
Signature
TarifSchedule
A class represent a concept A class encapsulates state (attributes) and behaviour (operations). Each attribute has a type. Each operation has a signature. The class name is the only mandatory information.
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 32
Bernd Bruegge & Allen H. Dutoit
Instances
tarif_2004:TarifSchedule zone2price = { {‘1’, .20}, {‘2’, .40}, {‘3’, .60}}
An instance represents a phenomenon. Instance name is underlined and can show its class. The attributes are shown with their values. No operation is shown as it is the same as for its class.
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
33
Actor vs Instances
Difference between actor, class and instance: Actor: external to the system interacts with the system E.g., “Passenger” Class: models an entity in the problem domain modelled inside the system E.g., “TariffSchedule” Instance: A specific instance of a class E.g., “tarif_2004, the specific TariffSchedule being used by the passenger for purchasing a ticket from the ticket distributor”
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 34
Bernd Bruegge & Allen H. Dutoit
Associations
TarifSchedule
TripLeg
Enumeration getZones() Price getPrice(Zone)
*
*
Price Zone
Associations denote relationships between classes. The multiplicity at an association end denotes how many objects the source object can legitimately reference.
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
35
1-to-1 and 1-to-many Associations
Country
name:String
Has-capital
CapitalCity name:String
One-to-one association
Has-vertex
Point
Polygon
*
x: Integer y: Integer
draw()
One-to-many association
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 36
Many-to-Many Associations
StockExchange
*
Lists
*
Company tickerSymbol
* StockExchange
Lists
tickerSymbol
1
Company
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
37
From Problem Statement To Object Model
Problem Statement: A stock exchange lists many companies. Each company is uniquely identified by a ticker symbol
Class Diagram:
StockExchange* Lists
*
Company tickerSymbol
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
38
From Problem Statement to Code
Problem Statement: A stock exchange lists many companies. Each company is identified by a ticker symbol
Class Diagram:
StockExchange
*
Lists
*
Company tickerSymbol
Java Code:
public class StockExchange { private Vector m_Company = new Vector(); }; public class Company { public int m_tickerSymbol; private Vector m_StockExchange = new Vector(); };
39
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Aggregation
An aggregation is a special case of association denoting a “consists of” hierarchy. The aggregate is the parent class, the components are the children class.
Exhaust system Exhaust system
1
Muffler diameter
0..2
Tailpipe
1
Muffler diameter
0..2
Tailpipe diameter
diameter
A solid diamond denotes composition, a strong form of aggregation where components cannot exist without the aggregate.
TicketMachine
3
ZoneButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 40
Qualifiers
Without qualification 1 Directory With qualification Directory filename * File filename
1
0…1
File
Qualifiers can be used to reduce the multiplicity of an association. Directory uses filename to make the association 1:1
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
41
Inheritance
Button
CancelButton
ZoneButton
The children classes inherit the attributes and operations of the parent class. Inheritance simplifies the model by eliminating redundancy.
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
42
Object modelling in Practice: Class Identification
Foo
Quantity
CustomerId Deposit() Withdraw() GetBalance()
Class Identification: Name of Class, Attributes and Methods
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
43
Object modelling in Practice: Encourage Brainstorming
Foo
Quantity CustomerId Deposit() Withdraw() GetBalance()
Account Quantity CustomerId
Naming is important! Is Foo the right name?
Deposit() Withdraw() GetBalance()
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
44
Object modelling in Practice contd.
Account Quantity AccountId CustomerId Deposit() Withdraw() GetBalance() Customer Name CustomerId
Bank Name
1) Find New Objects
2) Iterate on Names, Attributes and Methods
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
45
Object modelling in Practice: A Banking System
Account Quantity Bank Name AccountId CustomerId Deposit() Withdraw() GetBalance()
*
Customer Has Name CustomerId
1) Find New Objects 2) Iterate on Names, Attributes and Methods 3) Find Associations between Objects 4) Label the associations 5) Determine the multiplicity of the associations
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 46
Practice Object modelling: Iterate, Categorize!
Account Bank Name
*
Customer Amount AccountId Deposit() Withdraw() GetBalance()
*
Has
Name CustomerId CustomerId()
Savings Account
Checking Account
Mortgage Account
Withdraw()
Withdraw()
Withdraw()
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
47
Packages
A package is a UML mechanism for organizing elements into groups (usually not an application domain concept) Packages are the basic grouping constructs with which you may organise UML models to increase their readability.
DispatcherInterface
Notification
IncidentManagement
A complex system can be decomposed into subsystems, where each subsystem is modelled as a package
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 48
Bernd Bruegge & Allen H. Dutoit
Class Diagrams: Summary
Class diagrams: system structure Class: name, attributes (types), operations (signatures) Instances: underlined names, attribute values Associations between classes, multiplicities Qualified Associations: from many:many to 1:1 Aggregation, composition Inheritance Iterate udring class identification, naming, attributes and methods, associations Packages
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
49
UML sequence diagrams
Used during requirements analysis TicketMachine Passenger To refine use case descriptions selectZone() to find additional objects (“participating objects”) Used during system design insertCoins() to refine subsystem interfaces Classes are represented by pickupChange() columns Messages are represented by arrows pickUpTicket() Activations are represented by narrow rectangles Lifelines are represented by Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) dashed lines
50
Nested messages
Passenger
selectZone()
ZoneButton
TarifSchedule
Display
lookupPrice(selection) price
Dataflow
displayPrice(price)
…to be continued...
The source of an arrow indicates the activation which sent the message An activation is as long as all nested activations Horizontal dashed arrows indicate data flow Vertical dashed lines indicate lifelines
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 51
Bernd Bruegge & Allen H. Dutoit
Iteration & condition
…continued from previous slide...
Passenger
ChangeProcessor CoinIdentifier Display CoinDrop
*insertChange(coin)
Iteration
lookupCoin(coin) price displayPrice(owedAmount)
[owedAmount<0] returnChange(-owedAmount)
Condition
…to be continued...
Iteration is denoted by a * preceding the message name Condition is denoted by boolean expression in [ ] before the message name
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 52
Bernd Bruegge & Allen H. Dutoit
Creation and destruction
…continued from previous slide...
Passenger
ChangeProcessor
Creation
Ticket
createTicket(selection)
print() free()
Destruction
Creation is denoted by a message arrow pointing to the object. Destruction is denoted by an X mark at the end of the destruction activation. In garbage collection environments, destruction can be used to denote the end of the useful life of an object.
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 53
Bernd Bruegge & Allen H. Dutoit
Sequence Diagram Summary
UML sequence diagram represent behaviour in terms of interactions. Useful to find missing objects. Time consuming to build but worth the investment. Complements the class diagrams (which represent structure).
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
54
State Chart Diagrams
Event
[button1&2Pressed] BlinkHours
State
Initial state
[button2Pressed]
IncrementHrs
Transition
[button1&2Pressed] BlinkMinutes
[button1Pressed]
[button2Pressed] IncrementMin.
[button1Pressed] [button1&2Pressed] BlinkSeconds
[button2Pressed]
IncrementSec.
StopBlinking
Final state Represent behaviour as states and transitions
55
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Activity Diagrams
An activity diagram shows flow control within a system
Handle Incident Document Incident Archive Incident
An activity diagram is a special case of a state chart diagram in which states are activities (“functions”) Two types of states: Action state: Cannot be decomposed any further Happens “instantaneously” with respect to the level of abstraction used in the model Activity state: Can be decomposed further The activity is modelled by another activity diagram Note: UML 2 uses rounded rectangles for action and activity nodes.
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 56
Bernd Bruegge & Allen H. Dutoit
Statechart Diagram vs. Activity Diagram
Statechart Diagram for Incident (similar to Mealy Automaton) (State: Attribute or Collection of Attributes of object of type Incident)
Event causes State transition
Active IncidentHandled Inactive IncidentDocumented Closed IncidentArchived Archived
Activity Diagram for Incident (similar to Moore) (State: Operation or Collection of Operations)
Handle Incident Document Incident Archive Incident
Completion of activity causes state transition
Bernd Bruegge & Allen H. Dutoit
Triggerless Transition
57
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
Activity Diagram: modelling Decisions
[lowPriority] Open Incident Allocate Resources [fire & highPriority] [not fire & highPriority] Notify Fire Chief Notify Police Chief
Bernd Bruegge & Allen H. Dutoit
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick)
58
Activity Diagrams: modelling Concurrency
Synchronisation of multiple activities Splitting the flow of control into multiple threads
Allocate Resources
Splitting
Open Incident Coordinate Resources
Synchronisation
Archive Incident
Document Incident
Now Read BD Chapter 2
Object-Oriented Software Engineering: Using UML, Patterns, and Java L4 (Adapted For ISE 2005/6 By Ananda Amatya, University of Warwick) 59
Bernd Bruegge & Allen H. Dutoit
Get documents about "