Sei sulla pagina 1di 35

ECE651

Object-Oriented Analysis &


Design
Instructor:
Krzysztof Czarnecki

1
Overview
ÎWhat is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
• Domain modeling
• Behavioral modeling
– Design
• Interaction diagrams
• Refined class diagram
• Concurrency and scheduling
• Summary and Further Reading
2
OO Analysis & Design
• Analysis
– Domain level - modeling “real world” objects
– Really: part of requirements engineering
• requirements development = elicitation + analysis +
specification
– Many domain objects will not make into the design
– Domain structures often make poor design structures
• Design
– Assigning responsibilities to object
– Taking “illities” (maintainability, reusability, etc.) and
portability into account
3
– Devising mechanisms
OO Analysis & Design
• Many methods (OMT, Booch, Unified
Process, etc.)
• Similar goals and techniques

4
OO Analysis Activities
• Use case analysis
– Mostly focused on writing text - one overview context diagram is
often enough
– Use cases are just a part of functional requirements (only the
interactive ones)
• Structural analysis – domain modeling
– Finding the “real-world” objects involved in the use cases and
creating class diagrams to represent them
• Behavioral analysis
– Creating activity diagrams and sequence diagrams to capture use
case details
• Activity diagrams for business workflow
• Sequence diagrams for reactive behavior (also with timing)
– Possibly creating state charts to capture external reactive behavior
of the system and other domain objects 5
OO Design Activities
• Creating interaction diagrams and distributing
responsibilities
– Devising mechanisms and introducing design objects
– Creating sequence diagrams
– Creating communication (collaboration) diagrams
• Creating refined class diagrams
• Deciding on concurrency and scheduling model
• Possibly modeling detailed behavior of design
objects using state charts

6
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
ÎUse case modeling
• Domain modeling
• Behavioral modeling
– Design
• Interaction diagrams
• Refined class diagram
• Concurrency and scheduling
• Summary and Further Reading
7
Use Case Diagram As a Context
Diagram

Vending Machine

Use Case 1
Customer (Buy a drink)

8
Use Case Diagram As a Context
Diagram

Vending Machine

Use Case 1
Customer (Buy a drink)

Use Case 2
(Restock)
Agent

9
Different Forms of Use Cases
• “Casual version”
– User story
– A narrative
• Fully dressed
– Formal sections
• Preconditions
• Main scenario
• Exception list
• …
• See “Writing effective use cases” by Alistair
Cockburn, 2000
10
Use Case 1 (“Casual Version”)
Consider a simplified vending machine, which is used to dispense soft
drinks. The vending machine consists of a coin slot for inserting coins, a
return tray for returning the customer's money and three buttons used to
select Pepsi (tm), Coke (tm) or Dr. Pepper (tm). If the customer inserts
coins and does not press a button within one minute, the coins will be
returned automatically (no coin-return lever). If the customer selects a
beverage which is out-of-stock (none left), the coins will also be returned.
This vending machine does not provide change - it is up to the customer to
insert only enough money to purchase a drink. If sufficient coins are
inserted and a button with available beverages is pressed, the appropriate
drink is dispensed, the corresponding button is illuminated for five
seconds, and the coin slot moves the coins to the general storage area (i.e.
the purchase has finished).

11
Use Case 1 (“Fully Dressed” Version)
Primary actor: Customer
Goal in context: Customer buys a drink
Level: User level
Stakeholders and Interests:
Customer : wants to buy a drink
Vendor: wants to get paid for any goods dispensed
Preconditions: Machine is ready & awaiting interaction
Minimum guarantee: Customer gets his coins back if no drink dispensed
Success guarantees:
Customer has the drink; vending machine has the money for the
drink; Vending machine provides no change
Trigger: Customer starts interaction with the machine

12
Use Case 1 (Cont’d)
Main success scenario:
1. Customer inserts sufficient money into the coin slot
2. Customer pushes one of the three select buttons
3. The selected drink is dispensed.
4. The pushed select button lights up for 5 seconds.
5. Coins are taken by the machine.
Extensions
1a. Customer inserts no or insufficient money. Pushing a selection button has
no effect.
2a. Customer fails to push a button within 1 minute from insertion of the last
coin. Coins are returned.
2b. Customer selects beverage out of stock. Coins are returned.
Frequency of use: several per day
Priority: 1
Implementation status: … 13
Open issues: …
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
ÎDomain modeling
• Behavioral modeling
– Design
• Interaction diagrams
• Refined class diagram
• Concurrency and scheduling
• Summary and Further Reading
14
Noun analysis
Consider a simplified vending machine, which is used to dispense soft
drinks. The vending machine consists of a coin slot for inserting coins, a
return tray for returning the customer's money and three buttons used
to select Pepsi (tm), Coke (tm) or Dr. Pepper (tm). If the customer inserts
coins and does not press a button within one minute, the coins will be
returned automatically (no coin-return lever). If the customer selects a
beverage which is out-of-stock (none left), the coins will also be returned.
This vending machine does not provide change - it is up to the customer to
insert only enough money to purchase a drink. If sufficient coins are
inserted and a button with available beverages is pressed, the appropriate
drink is dispensed, the corresponding button is illuminated for five
seconds, and the coin slot moves the coins to the general storage area (i.e.
the purchase has finished).

15
Domain Model - Initial Class Diagram

Inserts
Contains
coins CoinSlot 1 1 0..*
into  Contains
amount 3 Shelf Drink
1 1
1
Vending Contains
1
Customer Machine 1
1
Button
Pushes Contains
id
3 Contains 1
litUp
ReturnTray

16
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
• Domain modeling
ÎBehavioral modeling
– Design
• Interaction diagrams
• Refined class diagram
• Concurrency and scheduling
• Summary and Further Reading
17
Sequence Diagram for Use Case 1
(Main Scenario + Extensions 1a & 2b)
customer machine
insertMoney(x)

insertMoney(y)
push(z)

m:=checkAmount(x+y)

a:=checkAvailability(z)
[!a] return()

[m&a] dispenseDrink()

lightUp()
5 sec moveCoins()
lightDown()
18
Activity Diagram for Use Case 1
(Main Scenario + Extension 1a)
Customer VendingMachine

Insert money

Select drink

money
Sufficient
money? no
yes

Dispense drink
drink
19
State Chart for Vending Machine
(Full behavior)
Insert money (x)
Push button Z
[no drink Z]/ after (60 seconds)/
return money return money

Ready
Push button Z [sufficient
money & drink Z in stock] after (5 seconds)/light down

Dispensing
Entry/
dispense drink,
light up button,
take money 20
Hierarchical State Chart

Insert money (x)

Coin slot Coin slot


empty has money

after (60 seconds)/return money


Push button Z [sufficient Push button Z [no drink Z]/return money
money & drink Z in stock] after (5 seconds)

Dispensing
Entry/
dispense drink,
light up button,
take money
21
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
• Domain modeling
• Behavioral modeling
– Design
ÎInteraction diagrams
• Refined class diagram
• Concurrency and scheduling
• Summary and Further Reading
22
Sequence Diagram
customer coinSlot button1 controller shelfRel1 shelfSens1
insertMoney(x)

insertMoney(y)
push() request(1)
close()

m:=checkAmount()

getTotal()
a:=checkAvailability()
isEmpty()

[!a] return()

[m&a] release()
lightUp()
moveCoins()
5 sec
open()
lightDown() 23
Extension 2a
customer coinSlot button1 controller timer
insertMoney(x) set(60)
insertMoney(y) set(60)

60 sec checkTime()

timeOut() checkTime()
return()

insertMoney(x) set(60)
insertMoney(y) set(60)

< 60 sec
push() request(1)
close() reset()

24
Communication Diagram
(Used to be collaboration diagram)
2: push()

button1

timer1 2.1: request(1)

2.1.5 [m&a]: lightUp()


2a: timeOut() 2.1.1: close()
1.1: set(60) 3.2.2: lightDown()
2.1.1.1: reset() 2.1.2.1: getTotal()
2.1.4a [!a]: return()
2.1.7 [m&a]: moveCoins() 2.1.4 [m&a]: release()
3.1.1: open() shelfRel
coinSlot controller
1: insertMoney(x) 2.1.3.1: isEmpty()
«self»
2.1.2: m:=checkAmount()

2.1.3: a:=checkAvailability() 2.1.6: set(5) shelfSens

3: timeOut()
timer2
25
Additional Design Technique: CRC Cards

• CRC (class-responsibility-
collaborator) cards
– Index cards
– Written in a design session
– Focus on assigning
responsibilities
– Can be used in addition to
interaction diagrams
– Pioneered by ward
Cunningham & Kent beck

26
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
• Domain modeling
• Behavioral modeling
– Design
• Interaction diagrams
ÎRefined class diagram
• Concurrency and scheduling
• Summary and Further Reading
27
Refined Class Diagram
Timer
CoinSlot set()
amount: Integer reset()
1
opened: Bool checkTime() ShelfSens
insertMoney(Int) Signals 3 empty: Bool
close() timeOut() isEmpty()
open()
getTotal() 1
return() 1
moveCoins()
1 Controller 1
1
Button price: Integer
id: Integer request(Integer)
litUp: Bool 1 checkAmount() 1
push() checkAvailability() ShelfRel
3
lightUp() 3

lightDown() release()

28
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
• Domain modeling
• Behavioral modeling
– Design
• Interaction diagrams
• Refined class diagram
ÎConcurrency and scheduling
• Summary and Further Reading
29
Single Thread With Passive Objects
• Requires a top level control loop
– Read input, compute, write output
• Calls to procedures performing the processing
steps need to be scheduled manually
• Simple: no synchronization of concurrent threads
or processes necessary
• May waste computing resources
– “Polling style”

30
Passive objects design with a
main control loop
// main control loop
while(true)
{
If (coinSlotSensor.coinInserted())
coinSlot.insertMoney(coinSlotSensor.amount()) ;
If (buttonSensor1.pressed()) button1.push();
If (buttonSensor2.pressed()) button2.push();
If (buttonSensor3.pressed()) button3.push();
timer1.checkTime();
timer2.checkTime();
}

31
Active Objects
• Define a statechart for each object
• Communication through signals
– E.g., SDL: asynchronous send, synchronous receive
– Synchronous communication requires sending a request
and waiting for the response
– Avoid variables shared between processes
• No direct support by most programming languages
– Need a framework/library
• Better utilization of computing resources
• Automatic scheduling
32
Overview
• What is OO Analysis & Design?
• Vending Machine Example
– Analysis
• Use case modeling
• Domain modeling
• Behavioral modeling
– Design
• Interaction diagrams
• Refined class diagram
• Concurrency and scheduling
ÎSummary and Further Reading
33
Summary
• Analysis
– Use case analysis - writing user stories
– Structural analysis/domain modeling - finding “real-world” objects
– Behavioral analysis
• Creating activity diagrams and sequence diagrams to capture use case
details
• Creating state charts to capture external reactive behavior of the
system and other domain objects
• Design
– Creating interaction diagrams and distributing responsibilities
– Creating refined class diagrams
– Deciding on concurrency and scheduling model
– Possibly modeling detailed behavior of design objects using state
charts
34
Further Reading
• Recommended OO Analysis & Design
book:
– Applying UML & Patterns: An Introduction to
Object-Oriented Analysis and Design and
Iterative Development” by Craig Larman, 3rd
edition, Prentice Hall, 2004

35

Potrebbero piacerti anche