Академический Документы
Профессиональный Документы
Культура Документы
Rectangle 8
Design
with Patterns, Process, and the UML
Introduction
Introduction
Welcome!
Introductions
– Course leader: Dr. Trần Vũ Bình
– Participants:
MSc. Nguyễn Ngọc Tú (Lecturer)
MSc. Phạm Thị Thu Trang (Lecturer)
Hồ Thuỵ Hương Thuỷ (Tutor)
Nguyễn Bá Trung (Tutor)
Prerequisites: Object-Oriented Programming
Logistics
Overview and Objectives
Learn how to “think in objects”
Requirements and analysis of the problem
domain
Design of a solution
– Assign responsibilities to objects
– Design patterns
– Architectural issues
– Java and/or C++ issues
Unified Process
UML
Practice!
Assessment components
Assignment 1
– Prepare requirement document
– Write use cases
– Develop Domain Model
Assignment 2
– Write Design Document
– Implement the system (desktop version)
– System Demo
Microsoft Visio
– Licensed software
– Installed on the lab PC
What is OOAD?
Lecture 1
What’s OOAD?
Functional decomposition and its problem
What’s UML?
Software Development Process
Library
Information
System
Catalogue Librarian
Book Library
Case:
– You are an instructor at a seminar. People in
your seminar have another class to attend
following yours, but don’t know where it is
located. One of your responsibilities is to
make sure everyone knows how to get to the
next class.
DiceGame
1 Includes
play()
roll()
fv1 := getFaceValue()
roll()
fv2 := getFaceValue()
DiceGame Die
die1 : Die 1 2 faceValue : int
die2 : Die
getFaceValue() : int
play() roll()
Hoa Sen University 25
Iterative and Evolutionary
Development
Iterative development
– Development is organized into a series of
short, fixed-length mini-projects called
iterations.
– the outcome of each is a tested, integrated,
and executable partial system.
– Known as iterative and incremental
development
3 weeks (for example)
Iterations are fixed in The system grows
length, or timeboxed. incrementally.
one iteration of design,
implement, integrate, and test
requirements workshops
Imagine this will
ultimately be a 20
iteration project.
requirements
requirements
software
software
In evolutionary iterative
development, the
requirements evolve
over a set of the early
iterations, through a
series of requirements
90% 90%
workshops (for
example). Perhaps
after four iterations and
50%
workshops, 90% of the
requirements are 30%
defined and refined. 20% 20%
5% 8% 10%
Nevertheless, only 2%
10% of the software is
Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5
built.
a 3week iteration
minor focus
User Interface
explore how to connect to
other layers
primary focus
of case studies
application Sale Payment
logic layer explore how to
design objects
other layers or secondary
Logging ... Database Access ...
components focus
Iteration 1
Iteration 2
Introduces just those
analysis and design Iteration 3
skills related to Additional analysis and
iteration one. design skills introduced.
Likewise.
Inception
Lecture 2
Recap
Inception overview
Evolutionary Requirements
Use cases
Other requirements
Assignment 1 instruction
Vision and Business Describe the high-level goals and constraints, the business case, and
Case provides an executive summary
Use-Case Model Describes the functional requirements. During inception, the names of
most use cases will be identified, and perhaps 10% of the use cases will
be analysed in detail
Supplementary Other requirements
specification
Glossary Key domain terminology, and data dictionary
Risk List & Risk Describes the risks (business, technical, resource, schedule) and ideas for
Management plan their mitigation or response
Prototypes and proof-of- To clarify the vision, and validate technical ideas
concepts
Iteration Plan Describes what to do in the first elaboration iteration
Phase Plan & Software Low-precision guess for elaboration phase duration and effort. Tools,
Development plan people, education, and other resources
Development Case A description of the customized UP steps and artefacts for this project.
Handle Returns
– Main Success Scenario: A customer arrives at a
checkout with items to return. The cashier uses
the POS system to record each returned item…
– Alternate Scenarios:
If they paid by credit, and the reimbursement
transaction to their credit account is rejected, inform the
customer and pay them with cash.
If the item identifier is not found in the system, notify the
cashier and suggest manual entry of the identifier code
If the system detects failure to communicate with the
external accounting system… (etc.)
Preconditions
– What must be true on start, and worth telling
the reader
– “Cashier is identified and authenticated”
Success Guarantee
– What must be true on successful completions,
and worth telling the reader
– “Sales is saved. Tax is correctly calculated…”
Special Requirements
– Related non-functional requirements
Touch screen UI on a large flat panel monitor
Language internationalization on the text displayed
Technology and Data Variation List
– Varying I/O methods and data formats (non-
functional constraints expressed by the
stakeholder)
Item identifier entered by laser scanner or keyboard
Credit account information entered by card reader or
keyboard
Enterprise Selling Things
Checkout Service
Sales Tax
Agency
POS System
Goal: Collect
taxes on sales Sales Activity
System Cashier
Customer
Process Sale alternate
notation for
Customer a computer
Payment system actor
Authorization
Service
Handle Returns
«actor»
actor Tax Calculator
Cashier
NextGen
«actor»
Process Sale Payment
Authorization
Service
Cashier
. . .
primary actors on supporting actors
the left on the right
NextGen Some UML alternatives to
illustrate external actors that
Process Sale «actor» are other computer systems.
Payment
«system» Authorization The class box style can be
Payment Payment Service used for any actor, computer or
Authorization Authorization human. Using it for computer
...
Service Service actors provides visual
distinction.
– Extensions:
7b. Paying by credit: Include Handle Credit Payment.
7c. Paying by check: Include Handle Check Payment
Process Sale
Cashier
«include» «include» «actor»
Accounting
«include» System
Handle Returns
Manage Users
...
Process Sale
Extension Points:
Payment UML notation:
VIP Customer 1. The extending use case
points to the base use case.
«extend»
Payment, if Customer 2. The condition and
presents a gift certificate extension point can be
shown on the line.
Handle Gift Certificate
Payment
Domain Model
Lecture 3
Recap
Case Requirements
Elaboration process
Domain model
– Introduction and definition
– How to create a domain model
Inception activities
Different types of requirements
Scenario & Use case
Writing Use Cases
Use Case Diagram
Use case relationships
Monopoly
– Implement a basic, key scenario of the Play
Monopoly Game use case: players moving
around the squares of the board
– Implement a start Up use case as necessary
to support the initialization needs of the
iteration
– Two to eight players can play
– A game is played as a series of rounds
Monopoly (cont)
– Play the game for only 20 rounds
– After the dice are rolled, the name of the player and
the roll are displayed. When the player moves and
lands on a square, the name of the player and the
name of the square that the player landed on are
displayed.
– In iteration-1 there is no money, no winner or loser, no
properties to buy or rent to pay, and no special
squares of any kind
– Square name will be “Go”, “Square 1”, “Square
2”,…“Square 39”
Hoa Sen University 90
Incremental Development
Therefore, different parts
Use Case Use Case Use Case or scenarios must be
Process Sale Process Sale Process Sale allocated to different
iterations.
Use Case
Process Rentals
Feature:
Logging
1..* *
Stockedin
association Containedin
1 1
Sale Store
1 Register
Capturedon
Payment
1
amount
Domain model is
visualization of a realworld concept in
a visualization of Sale
dateTime
the domain of interest
it is a not a picture of a software class
things in a real-
world domain of
interest av
o id
SalesDatabase
software artifact; not part
of domain model
Not suitable in a
domain model av
o id
date
Sale
software class; not part
of domain model
time
– Software artefacts print()
– Responsibilities or
methods
Hoa Sen University 99
What are conceptual classes
time
– Symbol – words or images
representing a conceptual
"A sale represents the event
class of a purchase transaction. It
has a date and time."
concept's intension
Sale
A Payment in the Domain Model Payment 1
1 Paysfor
is a concept, but a Payment in date
the Design Model is a software amount
time
class. They are not the same
thing, but the former inspired the
inspires
naming and definition of the
objects
latter.
and
names in
This reduces the representational
gap.
Sale
This is one of the big ideas in Payment
object technology. 1 1 date: Date
Paysfor
amount: Money startTime: Time
getBalance(): Money getTotal(): Money
. . .
UP Design Model
The objectoriented developer has taken inspiration from the real world domain
in creating software classes.
Therefore, the representational gap between how stakeholders conceive the
domain, and its representation in software, has been lowered.
Steps
– Find the conceptual classes
– Draw them as classes in a UML class diagram
– Add associations and attributes
Sales
Cashier Customer Ledger
LineItem
Class or attribute?
– If we do not think of some conceptual class X
as a number or text in the real world, X is
probably a conceptual class, not an attributes
description Worse
price
serial number
itemID
ProductDescription
Item
description Describes Better
price 1 * serial number
itemID
association
Recordscurrent
Register Sale
1 1
"reading direction arrow"
it has no meaning except to indicate direction of
reading the association label
often excluded
association name multiplicity
multiplicity of the role
Multiplicity should "1" or "0..1"?
The answer depends on our interest in using the model. Typically and practically, the muliplicity communicates a
domain constraint that we care about being able to check in software, if this relationship was implemented or
reflected in software objects or a database. For example, a particular item may become sold or discarded, and thus
no longer stocked in the store. From this viewpoint, "0..1" is logical, but ...
Do we care about that viewpoint? If this relationship was implemented in software, we would probably want to ensure
that an Item software instance would always be related to 1 particular Store instance, otherwise it indicates a fault or
corruption in the software elements or data.
This partial domain model does not represent software objects, but the multiplicities record constraints whose
practical value is usually related to our interest in building software or databases (that reflect our realworld domain)
with validity checks. From this viewpoint, "1" may be the desired value.
* Fliesto 1
Flight Airport
Fliesfrom
* 1
Product
Ledger Product Description
Catalog Contains
1 1..*
1 1
1
0..1 Records
Usedby Describes
accounts
Sales for * *
LineItem Store
Item
Stocks
1 1
* 1..*
1..*
1
Containedin Logs Houses
1 completed 1..*
Sale * Register
Capturedon
0..1 1
1 1 Isfor 1
Paidby Workson
1 1 1
Private visibility Public visibility readonly
attributes attribute with initialization Optional value
Most attribute
Cashier
“primitive” data
types Flight destination is a complex
Worse concept
association, not
with an attribute
Hoa Sen University 131
Data types as attributes
We sometimes represent what may initially be considered a number
or string as a new data type class in the domain model
We can show the data type only in attribute compartment or as a
separate class associated with another class.
ItemID Address
Product 1 1 1 1 street1
OK id Store
Description street2
manufacturerCode
countryCode cityName
...
Product Store
Description
OK address : Address
itemId : ItemID
Cashier
Worse a "simple" attribute, but being
name used as a foreign key to relate to
currentRegisterNumber another object
Cashier Register
Better 1 Workson 1
name number
Payment
not useful
amount : Number
Payment quantities are pure data
values, so are suitable to
amount : Quantity better
show in attribute section
Payment variation: Money is a
specialized Quantity whose
amount : Money unit is a currency
Lecture 4
Vision
UseCase Model
Process Sale
Process
Sale
use 1. Customer
case arrives ...
Cashier
names 2. Cashier
makes new
sale.
3. ... Glossary
parameters and
Require
Use Case Diagram Use Case Text return value details
ments
system
events
: System
Operation: : Cashier
enterItem(…) make Supplementary
system NewSale() Specification
Postconditions: operations
enterItem
. . .
(id, quantity)
starting events to design for
Design Model
: Register : ProductCatalog : Sale
enterItem
Design (itemID, quantity)
spec = getProductSpec( itemID )
addLineItem( spec, quantity )
the name could be "NextGenPOS" but "System" keeps it
simple
the ":" and underline imply an instance, and are explained in a
later chapter on sequence diagram notation in the UML
external actor to Process Sale Scenario
system
: Cashier :System
makeNewSale
endSale a message with
parameters
return value(s)
associated with the it is an abstraction
previous message total with taxes
representing the
system event of
an abstraction that entering the
ignores presentation makePayment(amount)
payment data by
and medium some mechanism
the return line is change due, receipt
optional if nothing is
returned
Process Sale Scenario
: Cashier :System
makeNewSale
Simple cashonly Process Sale scenario:
loop [ more items ]
1. Customer arrives at a POS checkout enterItem(itemID, quantity)
with goods and/or services to purchase.
2. Cashier starts a new sale.
3. Cashier enters item identifier. description, total
4. System records sale line item and
presents item description, price, and
running total.
Cashier repeats steps 34 until indicates
done. endSale
5. System presents total with taxes
calculated.
6. Cashier tells Customer the total, and total with taxes
asks for payment.
7. Customer pays and System handles
payment. makePayment(amount)
...
change due, receipt
:System
: Cashier
better name
enterItem(itemID, quantity)
scan(itemID, quantity)
worse name
Vision
UseCase Model
Process Sale
Process
Sale
use 1. Customer
case arrives ...
Cashier
names 2. ...
3. Cashier
enters item
identifier. Glossary
Require
Use Case Diagram Use Case Text
ments
ideas for system
the domain events requirements
the post
objects, that must be
conditions
attributes, satisfied by
: System
and the software
associations Operation: : Cashier
that undergo enterItem(…) make Supplementary
changes system NewSale() Specification
Postconditions: operations
enterItem
. . .
(id, quantity)
spec = getProductSpec( itemID )
addLineItem( spec, quantity )
To make contract
– Identify System Operations from SSD
– For system operations that are complex or
subtle in their results or are not clearly
express in use cases, construct a contract
– To describe the post conditions, use the
following categories
Instance creation and deletion
Attribute change of value
Associations (to be precise, UML links) formed and
broken
Hoa Sen University 147
System operations
Process Sale Scenario
:System
: Cashier
makeNewSale()
the system event enterItem
description, total invokes a system operation
called enterItem and so forth
this is the same as in object
oriented programming when
endSale() we say the message foo
invokes the method (handling
operation) foo
total with taxes
makePayment(amount)
change due, receipt
Operation: makeNewSale()
Cross References: Use Cases: Process Sale
Preconditions: none
Postconditions:
– A Sale instance s was created (instance creation).
– s was associated with a Register (association formed).
– Attributes of s were initialized.
Sequence diagrams
: A myB : B
illustrate interactions in a
doOne
kind of fence format doTwo
2: doThree
– More space-efficient
myB : B
«metaclass»
:Sale s1 : Sale
Font
List is an interface
lifeline box representing an lifeline box representing
instance of an ArrayList class, one instance of class Sale, in UML 1.x we could not use an
parameterized (templatized) to selected from the sales interface here, but in UML 2, this (or
hold Sale objects ArrayList <Sale> collection an abstract class) is legal
sales: x : List
sales[ i ] : Sale
ArrayList<Sale>
related
example
Lifeline boxes
: Register : Sale
and lifelines
doX
Messages doA
– Synchronous
doB
message a found message
whose sender will not
– Found message be specified doC
and execution
execution specification
specification bars bar indicates focus of
control typical sychronous message
shown with a filledarrow line
…
clear();
… : Register
}
doX
public void clear(){
clear
}
}
– In implementation: makePayment(cashTendered)
create(cashTendered) : Payment
create(cashTendered)
: Payment
– In language that the «destroy» stereotyped
... message, with the large
does not have X and short lifeline
indicates explicit object
garbage collection
«destroy»
X destruction
: A : B
makeNewSale
endSale
Conditional messages
public class foo{ : Foo : Bar
bar.xx();
if (color.equals(“red”)) yy
bar.calculate();
bar.yy(); : Foo : Bar
xx
}
}
[ color = red ] calculate
UML1.x style
yy
if (x < 10)
b.calculate(); [ else ]
calculate
else
c.calculate();
}
}
lineItems[i] :
: Sale This lifeline box represents one
SalesLineItem
instance from a collection of many
t = getTotal SalesLineItem objects.
lineItems[i] is the expression to
loop select one element from the
[ i < lineItems.size ]
st = getSubtotal collection of many
SalesLineItems; the ‘i” value
refers to the same “i” in the guard
i++
in the LOOP frame
an action box may contain arbitrary language
statements (in this case, incrementing ‘i’)
it is placed over the lifeline to which it applies
loop
st = getSubtotal
Nesting frames
: Foo : Bar
xx
loop(n)
calculate
: B : C
: A : B : C
authenticate(id)
doX
doA doM1
doB
doM2
authenticate(id) ref
AuthenticateUser
ref sd DoFoo
DoFoo
: B : C
interaction occurrence doX
note it covers a set of lifelines doY
note that the sd frame it relates to doZ
has the same lifelines: B and C
message to class, or a
static method call
doX
1: locs = getAvailableLocales «metaclass»
: Foo
Calendar
CreditPayment DebitPayment
Polymorphic messages and cases authorize() authorize()
... ...
object in role of abstract
polymorphic message
superclass
:Register :Payment {abstract}
doX
authorize stop at this point – don’t show any
further details for this message
authorize authorize
doA doX
doB
separate diagrams for each polymorphic concrete case
all messages flow on the same link
“this”
Creation of instances 1: clear
– Indicates a constructor
: Register :Sale {new}
1.1: msg3
not numbered
legal numbering
: C
third
1.1: msg3
2.1: msg5
2: msg4 : C
fourth fifth
2.2: msg6
sixth
: D
Conditional messages
conditional message, with test
– A conditional message is message1
true
1b [not test1] : msg4 1a.1: msg3
– Attach a letter to the
sequence number to : D 1b.1: msg5 : C
express mutually
exclusive message
Hoa Sen University 174
Collaboration diagram notation (cont)
Iteration or Looping
– Use a “*” to signify iteration
runSimulation 1 * [ i = 1..n ]: num = nextInt
: Simulator : Random
iteration is indicated with a * and an optional
iteration clause following the sequence number
this iteration and recurrence clause indicates This lifeline box represents one instance from a
we are looping across each element of the collection of many SalesLineItem objects.
lineItems collection.
lineItems[i] is the expression to select one
element from the collection of many
SalesLineItems; the ‘i” value comes from the
message clause.
Less precise, but usually good enough to imply
iteration across the collection members
message to class, or a
static method call
doX
1: locs = getAvailableLocales «metaclass»
: Foo
Calendar
authorize authorize
doA
doX
doB
:DebitPayment :Foo :CreditPayment :Bar
separate diagrams for each polymorphic concrete case
3: runFinalization
:ClockStarter System : Class
1: create
asynchronous message
2: run
active object
:Clock
Lecture 5
Notations
Dependency
Interaction and Class diagrams
Register Sale
Design Model ... time
1
isComplete : Boolean
DCD; software endSale() currentSale /total
perspective enterItem(...)
makePayment(...) makeLineItem(...)
Register Sale
OBSERVE: this style
visually emphasizes 1
... ...
the connection
currentSale
between these classes ... ...
using the association notation to indicate
Register has a reference to one Sale instance
Register Sale
thorough and
unambiguous, but some 1
currentSale : Sale ...
people dislike the
currentSale
possible redundancy ... ...
Register Sale
UP Domain Model 1 Capturescurrentsale 1
conceptual perspective id : Int time : DateTime
...
Two ways to show a
collection attribute
Sale SalesLineItem
1..*
time: DateTime ...
lineItems
... {ordered, List} ...
notice that an association end can optionally also
have a property string such as {ordered, List}
Register
«method»
// pseudocode or a specific language is OK ...
public void enterItem( id, qty )
{ endSale()
ProductDescription desc = catalog.getProductDescription(id); enterItem(id, qty)
sale.makeLineItem(desc, qty); makeNewSale()
} makePayment(cashTendered)
Note Symbols
– May represent several things
A UML note or comment
A UML constraint
A method body
...
Sale
...
...
updatePriceFor( ProductDescription )
... SalesLineItem
1..* ...
lineItems
...
...
Foo
runFinalization()
... ...
doX()
...
Stack
{
post condition: new size = old size – 1
}
Board
squares : List<K Square>
anonymous class with or
template binding complete T squares : List<Square>
ArrayList ...
elements : T[*]
ArrayList<T Square> ...
clear() clear()
... for example, the elements attribute is an
...
array of type T, parameterized and bound
before actual use.
there is a chance the UML 2 “arrow” symbol will
eventually be replaced with something else e.g., ‘=’
id : Int
...
doX()
...
exceptions thrown
DatabaseException
IOException
responsibilities
serialize and write objects
read and deserialize objects
...
makePayment(cashTendered)
makePayment(cashTendered)
messages in interaction
diagrams indicate operations
in the class diagrams classes
identified in the
interaction
diagrams are
Register Sale declared in the
1 class diagrams
... ...
currentSale
makePayment(…) makePayment(…)
... ...
Object Design
Lecture 6
Design activities
– Coding immediately
Using test-driven development
– Short UML modelling
Apply OO Design principles and design patterns
Design output
– UML diagrams for difficult parts of the system
– UI prototypes and database models
: Sale
makePayment(cashTendered)
create(cashTendered) : Payment
abstract, implies Sale objects have a
responsibility to create Payments
Problem
– Who creates the Square object
Start point: domain model
Problem
– Who creates an A object
Solution
– Assign class B the responsibility to create an
instance of class A if one of these is true
B “contains” A
B records A
B closely uses A
B has the Initializing data for A
Problem
– What is a general principle of assigning
responsibilities to objects
Solution
– Assign a responsibility to the class that has
the information needed to fulfil it
Problem
– How to reduce the impact of change, to
support low dependency, and increase reuse?
Solution
– Assign a responsibility so that coupling
remains low
Problem
– What first object beyond the UI layer receives and
coordinates (“controls”) a system operation
Solution
– Assign the responsibility to an object representing one
of these choices
– Represents the overall system, root object, device or
subsystem
– Represents a use case scenario within which the
system operations occurs
Problem
– How to keep objects focused,
understandable, and manageable, and as a
side effect, support Low Coupling?
Solution
– Assign responsibilities so that cohesion
remains high
Creator time
should be 1..*
Product
Sales Description
responsible for LineItem * Describedby 1
description
creating a quantity price
itemID
instance
makeLineItem(quantity)
– Solution: Sale create(quantity)
: SalesLineItem
contains many
SalesLineItem
objects.
Hoa Sen University 226
GRASP in POS project
Information Expert
Sale
Example
time
– Who should be 1
responsible for Contains
knowing the grand
1..*
total of a sale Product
Sales Description
– What information do LineItem * Describedby 1
description
quantity price
we need to compute itemID
the grand total
SalesLineItem
time
...
New method getTotal()
time
...
t = getTotal 1 *: st = getSubtotal lineItems[ i ] :
: Sale getTotal()
SalesLineItem
SalesLineItem
quantity
New method getSubtotal()
time
...
t = getTotal 1 *: st = getSubtotal lineItems[ i ] :
: Sale getTotal()
SalesLineItem
quantity
:Product getSubtotal()
Description
Product
Responsibility for each item price is assigned to the Description
ProductSpecification description
price
itemID
New method getPrice()
makePayment() 1: create()
: Register p : Payment
2: addPayment(p)
:Sale
makePayment() 1: makePayment()
: Register :Sale
1.1. create()
:Payment
presses button
: Cashier
actionPerformed( actionEvent )
system operation message
UI Layer :SaleJFrame
1: enterItem(itemID, qty)
controller
Domain Layer 1.1: makeLineItem(itemID, qty)
:Register :Sale
Represents the
overall “system”, enterItem(id, quantity)
:Register
“root object”,
device or
subsystem enterItem(id, quantity)
:ProcessSaleHandler
– Register
Represents a
receiver or handler
of all system
events of a user
case scenario
Hoa Sen University 234
Allocate system operations
System Register
endSale() ...
enterItem()
makeNewSale() endSale()
makePayment() enterItem()
makeNewSale()
makeNewReturn() makePayment()
enterReturnItem()
. . . makeNewReturn()
enterReturnItem()
. . .
system operations allocation of system
discovered during system operations during design,
behavior analysis using one facade controller
ProcessSale HandleReturns
System Handler Handler
allocation of system
operations during design,
using several use case
controllers
Façade controller
– PRO: all events handled in one place
– CON: can become too bloated
Use-case controller
– PRO: manage many different events across
different processes
– CON: adds additional classes; events can’t be
managed (e.g. logged) in one place
presses button
: Cashier
actionPerformed( actionEvent )
system operation message
UI Layer :SaleJFrame
1: enterItem(itemID, qty)
controller
Domain Layer 1.1: makeLineItem(itemID, qty)
:Register :Sale
presses button
Cashier
actionPerformed( actionEvent )
It is undesirable for an interface
layer object such as a window to get
UI Layer :SaleJFrame involved in deciding how to handle
domain processes.
Business logic is embedded in the
presentation layer, which is not useful.
1: makeLineItem(itemID, qty)
Domain Layer :Sale
SaleJFrame should not
send this message.
makePayment()
create()
p : Payment
addPayment( p )
: Register : Sale
makePayment()
makePayment()
create() : Payment
Lecture 7
Recap
Use Case Realization with GRASP
– POS project
– Monopoly Game project
Designing for visibility
Use case -> System events -> System sequence diagram ->
System operation contracts -> Interaction diagrams -> Design classes
each major interaction diagram starts with a system operation
going into a domain layer controller object, such as Register
makeNewSale 1: ???
:Register
Window objects
or
GUI widget objects . . . enterItem
:Register
1: ???
or
Web control objects
endSale 1: ???
:Register
UI LAYER DOMAIN LAYER
The system operations in the SSD are used as the start messages into the domain layer
If communication diagrams are used, one per system operation
Same for sequence diagram
: Register
makeNewSale
create
: Sale
Window objects
or
GUI widget objects . . .
or
Web control objects
: Register : ProductCatalog
enterItem(...)
desc = getProductDesc( itemID )
. . .
UI LAYER DOMAIN LAYER
create lineItems :
List<SalesLineItem>
this execution specification is implied to be
within the constructor of the Sale instance
enterItem(id, qty) 2: makeLineItem(desc, qty)
:Register :Sale
1: desc = getProductDesc(id) 2.1: create(desc, qty)
:Product
by Expert
Catalog
sl: SalesLineItem
1.1: desc = get(id)
2.2: add(sl)
lineItems :
: Map<ProductDescription> add the newly created
List<SalesLineItem>
SalesLineItem instance to the List
ProductDescription
ProductCatalog descriptions
{Map} description : Text
... price : Money
1 1..* itemID: ItemID
catalog getProductDesc(...)
...
description 1
Sale
Register isComplete : Boolean
time : DateTime lineItems SalesLineItem
... currentSale {ordered}
makeLineItem(...) quantity : Integer
enterItem(...) 1 1..*
...
... ...
«method»
public void getTotal()
{
int tot = 0;
for each SalesLineItem, sli
tot = tot + sli.getSubtotal();
return tot
}
1.1: pr = getPrice
:ProductDescription
Creating payment
by Controller by Creator and Low Coupling
makePayment(cashTendered) 1: makePayment(cashTendered)
:Register :Sale
1.1: create(cashTendered)
:Payment
... ...
* *
Logscompleted Logscompleted
1 1
Store SalesLedger
... ...
addSale(s : Sale) addSale(s : Sale)
... ...
Store is responsible for
SalesLedger is responsible
knowing and adding
for knowing and adding
completed Sales.
completed Sales.
Acceptable in early
Suitable when the design
development cycles if the
grows and the Store
Store has few
becomes uncohesive.
responsibilities.
note that the Sale instance is named
's' so that it can be referenced as a
parameter in messages 2 and 2.1
makePayment(cashTendered) 1: makePayment(cashTendered)
:Register s :Sale
2: addSale(s) 1.1: create(cashTendered)
by Expert
:Payment
:Store
2.1: add(s)
completedSales:
List<Sale>
{ bal = pmt.amount s.total }
2: t = getTotal
create 2: create(pc)
:Store :Register
by Creator
create an empty
collection object
1: create
1.1: create
1.2.1*: create(id, price, description)
1.2: loadProdSpecs()
pd:
the * in sequence number indicates the ProductDescription
message occurs in a repeating section
Two system
operations in the first
iteration
– Initialize
Ignore at this state
– Play game
Main focus
Choosing the
Controller Class
– Represents the overall
“system”, “root object”
MonopolyGame? *
– Represents a receiver
or handler of all system
events of a use case
scenario
PlayGameHandler?
Terminology
turn – a player rolling the dice and moving
the piece
round – all the players taking one turn
Game loop
for N rounds
for each player p
p takes a turn
: Register : ProductCatalog
enterItem
(itemID, quantity)
desc = getProductDesc( itemID )
public void enterItem( itemID, qty )
{
...
desc = catalog.getProductDesc(itemID)
...
}
class Register public void enterItem(itemID, qty)
{ {
... ...
private ProductCatalog catalog; desc = catalog.getProductDesc(itemID)
... ...
} }
: Register : ProductCatalog
enterItem
(itemID, quantity)
desc = getProductDesc( itemID )
enterItem(id, qty) 2: makeLineItem(desc, qty)
:Register :Sale
1: desc = getProductDesc(id)
2.1: create(desc, qty)
:Product
Catalog
makeLineItem(ProductDescription desc, int qty) sl : SalesLineItem
{
...
sl = new SalesLineItem(desc, qty);
...
}
enterItem(id, qty)
2: makeLineItem(desc, qty)
:Register :Sale
2: desc = getProductDesc(id)
2.1: create(desc, qty)
:Product
Catalog
sl : SalesLineItem
// initializing method (e.g., a Java constructor)
SalesLineItem(ProductDescription desc, int qty)
{
...
description = desc; // parameter to attribute visibility
...
}
: Register : ProductCatalog
enterItem
(itemID, quantity)
desc = getProductDesc( itemID )