Chapter 2, Modeling with UML Object-Oriented Software ...blk/cs4667/lectures/ch02.pdf · An...
Transcript of Chapter 2, Modeling with UML Object-Oriented Software ...blk/cs4667/lectures/ch02.pdf · An...
Usi
ng U
ML,
Pat
tern
s, an
d Ja
vaO
bjec
t-O
rien
ted
Soft
war
e E
ngin
eeri
ng Chapter 2,Modeling with UML
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
Overview: Modeling with UML
♦ What is modeling?♦ What is UML?♦ Use case diagrams♦ Class diagrams
Next lecture♦ Sequence diagrams♦ Activity diagrams
Then♦ Apply UML to Appalcart Project
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3
What is modeling?
♦ Modeling consists of building an abstraction of reality.♦ Abstractions are simplifications because:
They ignore irrelevant details andThey only represent the relevant details.
♦ What is relevant or irrelevant depends on the purpose of the model.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
Example: Appalcart route
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Why model software?
♦ Software is getting increasingly more complexWindows XP > 40 million lines of codeA single programmer cannot manage this amount of code in its entirety.
♦ Code is not easily understandable by developers who did not write it
♦ We need simpler representations for complex systemsModeling is a mean for dealing with complexity
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Systems, Models and Views
♦ A model is an abstraction describing a subset of a system♦ A view depicts selected aspects of a model♦ A notation is 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
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Systems, Models and Views
SystemView 1
Model 2View 2
View 3
Model 1
Aircraft
Flightsimulator
Scale Model
Blueprints
Electrical Wiring
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Models, Views and Systems (UML)
System Model View**
Depicted byDescribed by
Airplane: System
Blueprints: View Fuel System: View Electrical Wiring: View
Scale Model: Model Flight Simulator: Model
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Concepts and Phenomena
PhenomenonAn object in the world of a domain as you perceive itExample: The lecture you are attendingExample: My watch with a heart-rate monitor
ConceptDescribes the properties of phenomena that are common. Example: Lectures on software engineeringExample: All watches with a heart-rate monitor
Concept is a 3-tuple: Name (To distinguish it from other concepts)Purpose (Properties that determine if a phenomenon is a member of a concept) Members (The set of phenomena which are part of the concept)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
♦ AbstractionClassification of phenomena into concepts
♦ ModelingDevelopment of abstractions to answer specific questions about a set of phenomena while ignoring irrelevant details.
MembersName
Clock
Purpose
A device thatmeasures time.
Concepts and phenomena
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
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 possible instances the variable can take
The following relationships are similar:“type” <–> “instance”“concept” <–> “phenomenon”
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
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 behavior (methods)
Class ArrayList♦ Unlike abstract data types, classes can be
defined in terms of other classes using inheritance
Watch
timedate
CalculatorWatch
SetDate(d)
EnterCalcMode()InputNumber(n)
calculatorState
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
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 14
What is UML?
♦ UML (Unified Modeling Language)An emerging standard for modeling object-oriented software.Resulted from the convergence of notations from three leading object-oriented methods:
OMT (James Rumbaugh)OOSE (Ivar Jacobson)Booch (Grady Booch)
♦ Reference: “The Unified Modeling Language User Guide”, Addison Wesley, 1999.
♦ Supported by several CASE tools Rational ROSETogetherJ
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 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 16
UML First Pass
♦ Use case diagramsDescribe the functional behavior of the system as seen by the user.
♦ Class diagramsDescribe the static structure of the system: Objects, Attributes, Associations
♦ Sequence diagramsDescribe the dynamic behavior between actors and the system and between objects of the system
♦ Statechart diagramsDescribe the dynamic behavior of an individual object (essentially a finite state automaton)
♦ Activity diagramsModel the dynamic behavior of a system, in particular the workflow (essentially a flowchart)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
UML first pass: Use case diagrams
WatchUser WatchRepairPerson
ReadTime
SetTime
ChangeBattery
Actor
Use casePackageWatch
Use case diagrams represent the functionality of the systemfrom user’s point of view
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
UML first pass: Class diagrams
1
2
push()release()
1
1
blinkIdxblinkSeconds()blinkMinutes()blinkHours()stopBlinking()referesh()
LCDDisplay Batteryload
1
2
1
Timenow
1
Watch
ClassAssociation
Multiplicity
Attribute Operations
Class diagrams represent the structure of the system
state
PushButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
UML first pass: Sequence diagram
:LCDDisplay
blinkHours()
blinkMinutes()
refresh()
com mitNewTime()
:Time
incrementMinutes()
stopBlinking()
:Watch
pressButton1()
pressButton2()
pressButtons1And2()
pressButton1()
:WatchUser
Object
Message
Activation
Sequence diagrams represent the behavior as interactions
Actor
Lifeline
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
UML first pass: Statechart diagrams for objects with interesting dynamic behavior
BlinkHours
BlinkMinutes
IncrementHrs
IncrementMin.
BlinkSeconds IncrementSec.
StopBlinking
[button1&2Pressed]
[button1Pressed]
[button2Pressed]
[button2Pressed]
[button2Pressed]
[button1Pressed]
[button1&2Pressed]
[button1&2Pressed]
StateInitial state
Final state
Transition
Event
Represent behavior as states and transitions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Other UML Notations
UML provide other notations that we will be introduced in subsequent lectures, as needed.
♦ Implementation diagramsComponent diagramsDeployment diagramsIntroduced in lecture on System Design
♦ Object constraint languageIntroduced in lecture on Object Design
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
UML Core Conventions
♦ Rectangles are classes or instances♦ Ovals are functions or use cases♦ Instances are denoted with an underlined names
my Watch:SimpleWatch
Joe:Firefighter
♦ Types are denoted with non underlined namesSimpleWatch
Firefighter
♦ Diagrams are graphsNodes are entitiesArcs are relationships between entities
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
Use Case Diagrams
♦ Used during requirements elicitation to represent external behavior
♦ Actors represent roles, that is, a type of user of the system
♦ Use cases represent a sequence of interaction for a type of functionality
♦ The use case model is the set of all use cases. It is a complete description of the functionality of the system and its environment
Passenger
PurchaseTicket
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Actors
♦ An actor models an external entity which communicates with the system:
UserExternal systemPhysical environment
♦ An actor has a unique name and an optional description.
♦ Examples:Passenger: A person in the trainGPS satellite: Provides the system with GPS coordinates
Passenger
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 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 26
Use Case Diagram: Example
Name: Purchase ticket
Participating actor: Passenger
Entry condition:♦ Passenger standing in front of
ticket distributor.♦ Passengerhas sufficient money
to purchase ticket.
Exit condition:♦ Passengerhas ticket.
Event flow:1. Passengerselects the number of
zones to be traveled.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!
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
The <<extends>> Relationship♦ <<extends>> relationships
represent exceptional or seldom invoked cases.
♦ The exceptional event flows are factored out of the main event flow for clarity.
♦ Use cases representing exceptional flows can extend more than one use case.
♦ The direction of a <<extends>>relationship is to the extended use case
Passenger
PurchaseTicket
TimeOut
<<extends>>
NoChange
<<extends>>OutOfOrder
<<extends>>
Cancel
<<extends>>
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
The <<includes>> Relationship
♦ <<includes>> relationship represents behavior that is factored out of the use case.
♦ <<includes>> behavior is factored out for reuse, not because it is an exception.
♦ The direction of a <<includes>>relationship is to the using use case (unlike <<extends>>relationships).
Passenger
PurchaseSingleTicket
PurchaseMultiCard
NoChange
<<extends>>
Cancel
<<extends>>
<<includes>>
CollectMoney
<<includes>>
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29
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 provide meat of model, not the use case
diagrams.♦ All use cases need to be described for the model to be useful.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30
Class Diagrams
♦ Class diagrams represent the structure of the system.♦ Used
during requirements analysis to model problem domain conceptsduring system design to model subsystems and interfacesduring object design to model classes.
Enumeration getZones()Price getPrice(Zone)
TarifSchedule
* *Trip
zone:ZonePrice: Price
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
Classes
♦ A class represent a concept♦ A class encapsulates state (attributes) and behavior (operations).♦ Each attribute has a type.♦ Each operation has a signature.♦ The class name is the only mandatory information.
zone2pricegetZones()getPrice()
TarifSchedule
Table zone2priceEnumeration getZones()Price getPrice(Zone)
TarifSchedule
Name
Attributes
Operations
Signature
TarifSchedule
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32
Instances
♦ An instance represents a phenomenon.♦ The name of an instance is underlined and can contain the class of the
instance.♦ The attributes are represented with their values.
zone2price = {{‘1’, .20},{‘2’, .40},{‘3’, .60}}
tarif_1974:TarifSchedule
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33
Actor vs Instances
♦ What is the difference between an actor, a class and an instance?
♦ Actor: An entity outside the system to be modeled, interacting with thesystem (“Passenger”)
♦ Class: An abstraction modeling an entity in the problem domain, must bemodeled inside the system (“User”)
♦ 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 34
PriceZone
Associations
♦ Associations denote relationships between classes.♦ The multiplicity of an association end denotes how many objects the source
object can legitimately reference.
Enumeration getZones()Price getPrice(Zone)
TarifSchedule TripLeg
* *
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
1-to-1 and 1-to-many Associations
Country
name:String
City
name:String
Has-capital
Polygon
draw()
Point
x: Integer
y: Integer
One-to-one association
One-to-many association
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36
Many-to-Many Associations
StockExchange Company
tickerSymbol
Lists **
StockExchange CompanyLists 1*
tickerSymbol SX_ID
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37
From Problem Statement To Object Model
Problem Statement: A stock exchange lists many companies. Each company is uniquely identified by a ticker symbol. A company may be listed on more than one stock exchange.
Class Diagram:
StockExchange Company
tickerSymbolLists
**
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38
From Problem Statement to Code
public class StockExchange{private ArrayList m_Company = new ArrayList();};
public class Company{
public int m_tickerSymbol;private ArrayList m_StockExchange = new ArrayList();
};
Class Diagram:
Java Code
StockExchange Company
tickerSymbolLists **
Problem Statement: A stock exchange lists many companies. Each company is uniquely identified by a ticker symbol. A company may be listed on more than one stock exchange.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39
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.
♦ A solid diamond denotes composition, a strong form of aggregation where components cannot exist without the aggregate. (Bill of Material)
TicketMachine
ZoneButton3
Exhaust system
Muffler
diameter
Tailpipe
diameter
1 0..2
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40
Book ChapterN
composed-of
Booch
Book Chapter
composed-of
UML1 *
Figure 2-7, Example of describing a model with two different notations.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41
Qualifiers
♦ Qualifiers can be used to reduce the multiplicity of an association.
DirectoryFile
filename
Without qualification1 *
With qualification
Directory File0…11
filename
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42
Inheritance
♦ The children classes inherit the attributes and operations of the parent class.
♦ Inheritance simplifies the model by eliminating redundancy.
Button
ZoneButtonCancelButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43
Object Modeling in Practice: Class Identification
Foo
AmountCustomerId
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 44
Object Modeling in Practice: Encourage Brainstorming
Foo
AmountCustomerId
Deposit()Withdraw()GetBalance()
Account
AmountCustomerId
Deposit()Withdraw()GetBalance()
Naming is important! Is Foo the right name?
“Dada”
AmountCustomerId
Deposit()Withdraw()GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45
Object Modeling in Practice
Account
Amount
Deposit()Withdraw()GetBalance()
Customer
NameCustomerId
1) Find New Objects
CustomerIdAccountId
2) Iterate on Names, Attributes and Methods
Bank
Name
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46
Object Modeling in Practice: A Banking System
Account
Amount
Deposit()Withdraw()GetBalance()
Customer
NameCustomerId
CustomerIdAccountIdBank
Name
1) Find New Objects
2) Iterate on Names, Attributes and Methods
3) Find Associations between Objects
Has
4) Label the assocations5) Determine the multiplicity of the assocations
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47
Practice Object Modeling: Iterate, Categorize!
Customer
Name
CustomerId()
Account
Amount
Deposit()Withdraw()GetBalance()
CustomerIdAccountId
Bank
Name Has**
SavingsAccount
Withdraw()
CheckingAccount
Withdraw()
MortgageAccount
Withdraw()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48
Watch
timedate
CalculatorWatchSetDate(d)
EnterCalcMode()InputNumber(n)
calculatorState
Figure 2-8, A UML class diagram depicting two classes: Watch and CalculatorWatch. CalculatorWatch is a refinement of Watch, providing calculator functionality normally not found in normal Watches.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49
OrganicCompound
Benzene
Figure 2-9, An example of abstract class.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50
Watch
CalculatorWatch
simpleWatch1291:Watch
calculatorWatch1515:CalculatorWatch
«instanceOf»
«instanceOf»
Figure 2-10, A UML class diagram depicting instances of two classes.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51
Packages
♦ A package is a UML mechanism for organizing elements into groups (usually not an application domain concept)
♦ Packages are the basic grouping construct with which you may organize UML models to increase their readability.
♦ A complex system can be decomposed into subsystems, where each subsystem is modeled as a package
DispatcherInterface
Notification IncidentManagement
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52
UML sequence diagrams
♦ Used during requirements analysisTo refine use case descriptionsto find additional objects (“participating objects”)
♦ Used during system design to refine subsystem interfaces
♦ Classes are represented by columns
♦ Messages are represented by arrows
♦ Activations are represented by narrow rectangles
♦ Lifelines are represented by dashed lines
selectZone()
pickupChange()
pickUpTicket()
insertCoins()
PassengerTicketMachine
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 53
Nested messages
♦ 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
selectZone()
PassengerZoneButton TarifSchedule Display
lookupPrice(selection)
displayPrice(price)
price
Dataflow
…to be continued...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 54
Iteration & condition
♦ Iteration is denoted by a * preceding the message name♦ Condition is denoted by boolean expression in [ ] before the message
name
PassengerChangeProcessor
insertChange(coin)
CoinIdentifier Display CoinDrop
displayPrice(owedAmount)
lookupCoin(coin)
price
[owedAmount<0]returnChange(-owedA mount)
Iteration
Condition
…to be continued...
…continued from previous slide...
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 55
Creation and 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.
PassengerChangeProcessor
…continued from previous slide...
Ticket
createTicket(selection)
free()
Creation
Destruction
print()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 56
Sequence Diagram Summary
♦ UML sequence diagram represent behavior in terms of interactions.
♦ Useful to find missing objects.♦ Time consuming to build but worth the investment.♦ Complement the class diagrams (which represent structure).
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 57
State Chart Diagrams
BlinkHours
BlinkMinutes
IncrementHrs
IncrementMin.
BlinkSeconds IncrementSec.
StopBlinking
[button1&2Pressed]
[button1Pressed]
[button2Pressed]
[button2Pressed]
[button2Pressed]
[button1Pressed]
[button1&2Pressed]
[button1&2Pressed]
StateInitial state
Final state
Transition
Event
Represent behavior as states and transitions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 58
Group Work
The following sequence of diagrams are taken from an example developed in the textbook. We will review UML notation by trying to understand these diagrams.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 59
Report Emergency
FieldOfficer DispatcherOpenIncident
AllocateResources
FRIEND
Figure 2-13, An example of a UML use case diagram: Incident initiation in an accident management system.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 60
OpenIncident
AllocateResources
HelpDispatcher«include»
«include»
Figure 2-16, An example of an «include»relationship.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 61
Figure 2-18, An example of an «extend»relationship.
OpenIncident
AllocateResources
ConnectionDown«extend»
«extend»
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 62
EmergencyReport Incident
FieldOfficer
name:StringbadgeNumber:Integer
Dispatcher
name:StringbadgeNumber:Integer
author
incidentsGeneratedreportsGenerated
initiator
reports
1
*
1
*1..*
1
Figure 2-22, An example of a UML class diagram: classes that participate in the ReportEmergency use case.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 63
report_1291 incident_1515bob:FieldOfficer
name = “Bob D.”badgeNumber = 132
john:Dispatcher
name = “John D.”badgeNumber = 12
alice:FieldOfficer
name = “Alice W.”badgeNumber = 23
Figure 2-23, An example of a UML object diagram: objects that participate in the warehouseOnFirescenario.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 64
IncidentFieldOfficer
name:StringbadgeNumber:Integer
Allocates
role:StringnotificationTime:Time
resourcesincident
1
1..*
Figure 2-25, An example of an association class.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 65
Incident
FieldOfficer
name:StringbadgeNumber:Integer
Allocation
role:StringnotificationTime:Time
resources
incident 1
1..*
11
Figure 2-26, Alternative model for Allocation.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 66
EmergencyReport Incident
FieldOfficer Dispatcherauthor initiator
reportsGenerated incidents
1
*1
*
1..*
1
PoliceOfficer
name:StringbadgeNumber:Integer
Figure 2-32, An example of a generalization.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 67
Report Emergency
FieldOfficer
DispatcherOpenIncident
AllocateResources
ArchiveIncident
SearchArchive
ManageUsers
ManageTerminalsLibrarian SysAdmin
SysAdministrationIncidentArchive
IncidentManagement
Figure 2-45, Example of packages: use cases of FRIEND organized by actors.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 68
FieldOfficer Dispatcher
Librarian SysAdmin
IncidentArchive SysAdministration
IncidentManagement
Figure 2-46, Example of packages.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 69
DispatcherStation
EmergencyReport Incident
FieldOfficer Dispatcher
FieldStation
Figure 2-47, Example of packages.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 70
EmergencyReport
DispatcherStation
Incident
FieldOfficer Dispatcher
FieldStation
The EmergencyReportclass is defined in FieldStationand used in both stations.
Figure 2-48, An example of a note. Notes can be attached to a specific element in a diagram.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 71
Activity Diagrams
♦ An activity diagram shows flow control within a system
♦ 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 furtherHappens “instantaneously” with respect to the level of abstraction used in the model
Activity state:Can be decomposed furtherThe activity is modeled by another activity diagram
HandleIncident
DocumentIncident
ArchiveIncident
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 72
Statechart Diagram vs. Activity Diagram
HandleIncident
DocumentIncident
ArchiveIncident
Active Inactive Closed Archived
Incident-Handled
Incident-Documented
Incident-Archived
Statechart Diagram for Incident (similar to Mealy Automaton)(State: Attribute or Collection of Attributes of object of type Incident)
Activity Diagram for Incident (similar to Moore(State: Operation or Collection of Operations)
TriggerlessTransitionCompletion of activity
causes state transition
Event causesState transition
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 73
Activity Diagram: Modeling Decisions
OpenIncident
NotifyPolice Chief
NotifyFire Chief
AllocateResources
[fire & highPriority]
[not fire & highPriority]
[lowPriority]
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 74
Activity Diagrams: Modeling Concurrency
♦ Synchronization of multiple activities ♦ Splitting the flow of control into multiple threads
OpenIncident
AllocateResources
CoordinateResources
DocumentIncident
ArchiveIncident
SynchronizationSplitting
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 75
Activity Diagrams: Swimlanes
♦ Actions may be grouped into swimlanes to denote the object or subsystem that implements the actions.
OpenIncident
AllocateResources
CoordinateResources
DocumentIncident
ArchiveIncident
Dispatcher
FieldOfficer
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 76
What should be done first? Coding or Modeling?
♦ It all depends….
♦ Forward Engineering:Creation of code from a modelGreenfield projects
♦ Reverse Engineering:Creation of a model from codeInterface or reengineering projects
♦ Roundtrip Engineering:Move constantly between forward and reverse engineeringUseful when requirements, technology and schedule are changing frequently
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 77
UML Summary
♦ UML provides a wide variety of notations for representing many aspects of software development
Powerful, but complex languageCan be misused to generate unreadable modelsCan be misunderstood when using too many exotic features
♦ For now we concentrate on a few notations:Functional model: Use case diagramObject model: class diagramDynamic model: sequence diagrams, statechart and activity diagrams