Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Case study

OOAD
322
Case study

□ Problem
■ A very simple problem to show the use of UML in analysis and design
■ It is taken from the “Applying UML and Patterns” book of Claig Larman

■ A dice game
□ They player rolls 10 times 2 dice. If the total of two dice is 7, he
gains 10 points. At the end of the game, the score is saved to the
scoreboard

OOAD
323
Main Activities of Software Development

Requirements
Analysis Design
Gathering
Design the solution /
Define requirement Define the conceptual model
software plan
specification

Implementation Integration and Test Deployment


Code the system based on Prove that the system meets
Installation and training
the design the requirements

Maintenance
Post-install review
Support docs
Active support

OOAD
324
Case study

□ Requirement analysis
■ Use-case diagram

Play

Player View High Score

■ Use-case: Play
□ Description: The player rolls 2 dice 10 times. If each time the total
is 7, he receives 10 points.

■ Use-case: View High Score


□ Description: They player consults the scores

OOAD
325
Case study

□ Requirement analysis
■ Activity diagram
□ Some activities are linked to the graphical user interface

[view]
[play] [exit]

View High Score Play

Roll dice

[true]

Turn < 10 [false]

Update High Score

OOAD
326
Use-case

□ Requirement analysis
■ Activity diagram
□ The relationship between the use-case diagram and activity diagram

Menu

[view]
[play] [exit]

Play View High Score Play

Roll dice
View High Score
Player Turn < 10
[true]

[false]

Update High Score

OOAD
327
Main Activities of Software Development

Requirements
Analysis Design
Gathering
Design the solution /
Define requirement Define the conceptual model
software plan
specification

Implementation Integration and Test Deployment


Code the system based on Prove that the system meets
Installation and training
the design the requirements

Maintenance
Post-install review
Support docs
Active support

OOAD
328
Case study

□ Analysis

■ Modelling the real world

■ Independent of the implementation

■ Modelling of the domain: conceptual class diagram

■ Modelling of the dynamic behaviour of the system:


collaboration diagram

OOAD
329
Case study

□ Modeling of conceptual class diagram

rolls
Player Die

1 2

1 2

plays
includes
DiceGame
1
1

1
scoring
1

HighScore

OOAD
330
Case study

□ A first collaboration diagram

s() d1:Die
ll
ro
2:
1: play()
3: r
:DiceGame :Player olls
()

d2:Die

OOAD
331
Case study

□ A first class diagram

rolls
Player
Die
-name
1 2 -faceValue : int = 1
-score : int = 0
+rolls()
+play()

2
1

plays
includes
DiceGame
1
1

1
scoring
1

HighScore

OOAD
332
Case study

□ Collaboration diagram and class diagram

rolls
Player
Die
-name
1 2 -faceValue : int = 1
-score : int = 0
+rolls()
+play()

2
1

plays
includes
DiceGame
1
1

) d1:Die
ro lls( 1
2: scoring
1: play() 1
3: r
:DiceGame :Player olls HighScor
()

d2:Die

OOAD
333
Case study

□ Sequence diagram

:DiceGam :Player d1:Die d2:Die

1: play()
2: rolls()

3: rolls()

OOAD
334
Case study

□ The creation of objects at the beginning of the game (DiceGame) for a


player

:DiceGame d1:Die d2:Die :Player


:RealPlayer
1: DiceGame()

2: Die()

3: Die()

4: start()

Player(name)

OOAD
335
Case study

□ State diagram: modelling the states of the DiceGame

cancel

start game
start
Ready to Play Player ready
exit

cancel play

[turn >= 10]


In progress

rolls die [turn < 10]

OOAD
336
Case study

□ Detection of inconsistency between the activity diagram and the state


diagram

Menu
cancel

[view] start game


[play] [exit] start
Ready to Play Player ready
View High Score Play exit

cancel play
Roll dice
[turn >= 10]
Turn < 10 In progress
[true]

[false] rolls die [turn < 10]

Update High Score

OOAD
337
Case study

□ Modification of the activity diagram as well as the envisaged graphical


user interface

OOAD
338
Case study

□ The treatment of the scoreboard must be taken into account: the update
and the creation

Menu

[view]
[play] [exit]

Play View High Score Play

Roll dice
View High Score
Player Turn < 10
[true]

[false]

Update High Score

No treatment

OOAD
339
Case study

□ Sequence diagram: manage high score, create new player

:DiceGame d1:Die d2:Die :Player :HighScore


:RealPlayer
1: DiceGame()

2: Die()

3: Die()

4: HighScore()
5: start()

6: Player(name)

OOAD
340
Case study

□ Sequence diagram: add high score to score board

:DiceGame :Player d1:Die d2:Die :Entry :HighScore

1: Player()

2: play() 3: rolls()

4: rolls()

5: Entry(name, score)

6: add(:Entry)

OOAD
341
Case study

□ Class diagram

Player rolls
Die
-name
1 -faceValue : int = 1
-score : int = 0 2
+rolls()
+play()
+Die()
+Player()()

2
1
plays
DiceGame includes
1
+DiceGame() 1
+start()

1 scoring
1

HighScore contains Entry


-name
1 * -score
+HighScore()
+add(Entry)() +Entry(name, score)()

OOAD
342
Main Activities of Software Development

Requirements
Analysis Design
Gathering
Design the solution /
Define requirement Define the conceptual model
software plan
specification

Implementation Integration and Test Deployment


Code the system based on Prove that the system meets
Installation and training
the design the requirements

Maintenance
Post-install review
Support docs
Active support

OOAD
343
Case study

□ Design

■ Take into account the implementation

□ Manage the graphical user interface part

□ Manage the persistence of scoreboard

■ Define the logical architecture

■ Define the physical architecture

■ Introduce the technical class permitting to implement the


architecture

OOAD
344
Case study

□ General architecture
■ Classical three layer architecture

Presentation

View High Score


Business Logic Play

Persistence

OOAD
345
Case study

□ A package diagram corresponds to the architecture

UI

UI : presentation layer
Core : Business logic layer Core Util
DB : Persistence layer
Util : utility services/classes/functionalities

DB

OOAD
346
Case study

□ Use design patterns to improve the classes of “Core” package

Player rolls
Die
-name
1 -faceValue : int = 1
-score : int = 0 2
La classe DiceGame ne possède +play()
+rolls()
+Die()
+Player()
qu’un seul objet
La classe HighScore ne possède 1
2

qu’un seul objet plays


DiceGame includes
1
+DiceGame() 1
+start()

Le patron de conception : Singleton 1


1 scoring

HighScore contains Entry


-name
1 * -score
+HighScore()
+add() +Entry(name, score)()

OOAD
347
Case study

□ Singleton design pattern

Singleton
static uniqueSingleton
other attributs …
return uniqueSingleton;
static instance()
other operations …

■ Application to DiceGame and HighScore.

OOAD
348
Case study

□ Modified class diagram

Player rolls Die


-name -faceValue : int = 1
-score : int = 0 1 2
+rolls()
+play() +Die()
+Player() +display()
+display()
-dice
-player 2
1
DiceGame
-$dg : DiceGame = null 1
1 +DiceGame()
+start()
+getInstance() : DiceGame
private static HighScore hs = null;

HighScore
contains Entry
-$hs : HighScore = null
-name
+HighScore() 1 * -score
public static HighScore getInstance{ +getInstance() : HighScore
return HighScore; +add() +Entry(name, score)()
} +load()
+save()

OOAD
349
Case study

□ Observer design pattern

Subject Observer
observer
attach(o Observer) update()
dettach(o Observer)
for all o in observer
notify() o.update()

ConcreteSubject ConcreteObserver
subject
getState() update()
setState() observerState
subjectState return subjectState;

observerState=
subject.getState()

OOAD
350
Case study

□ Application of Observer design pattern to improve the class diagram


■ Decouple the graphical views and objects for the dice and players
■ Application of Observer pattern
□ Die and Player classes are ConcreteSubject class
□ Introduce DieView et PlayerView as ConcreteObserver classes

Observable
-changed : bool = false «interface»
Observer
+notifyObserrvers()
+addObserver() +update(o : Observable, arg : Object)()
+...()

Player Die
-name -faceValue : int = 1
-score : int = 0 +rolls()
+play() +Die()
+Player() +display() DieView
+display()
+DieView(die : Die)()
PlayerView +update(o : Observable, arg : Object)()

+PlayerView(player : Player )()


+update(o : Observable, arg : Object)()

OOAD
351
Case study

□ User view are instances of javax.swing.JPanel.java

Observable
-changed : bool = false «interface»
Observer
+notifyObserrvers ()
+ update (o : Observable , arg : Object )()
+addObserver ()
+...()

JPanel

Player Die
-name -faceValue : int = 1
-score : int = 0 +rolls ()
+play () +Die ()
+Player () +display () DieView
+display ()

+DieView (die : Die )()


PlayerView +update (o : Observable , arg : Object )()

+PlayerView (player : Player )()


+update (o : Observable , arg : Object )()

OOAD
352
Case study

□ Sequence diagram describes the interactions between Die object the its
view

:Die :Ramdomize :DieView

1:getValue()

2:setValue()

3:notifyObservers()

4:update(Observable, Object)

OOAD
353
Case study

□ The design of “UI” package

OOAD
354
Case study

□ The design of “Util” package

:Player :Die :Randomizer :Random

1:roll()
Singleton
2:getInstance()
Randomizer

+getInstance() 3:Randomizer()
+getValue()
4:Random()

5:getValue()
Random
6:nextInt()

OOAD
355
Case study

□ The design of “DB” package


■ How to ensure the independence between “Core” and “DB” package
□ In order to be able to use several persistence types
■ File (serialisation)
■ Relation Database Management System (via JDBC)

□ Use FactoryMethod design pattern


Creator product = factoryMethod();
* 1 factoryMethod() …
Product anOperation()

ConcreteProduct CreateCreator return new ConcreteProduct();


factoryMethod()

<<create>>

OOAD
356
Case study

□ The design of “DB” package


■ Class diagram

HighScore DBKit

- $ hs : HighScore = null - :

+ HighScore () + makeKit ()
+ getInstance () : HighScore
+ add ()
+ load ()
+ save ()

FileKit JDBCKit
HighScoreFile
HighScoreJDBC

+ makeKit () + makeKit ()
+ HighScoreFile ()
+ HighScoreJDBC ()
+ load ()
+ load ()
+ save ()
+ save ()

<< create >>

Note : HighScore class is a Singleton

OOAD
357
Case study

□ The design of the “DB” package


■ Sequence diagram

:RealPlayer :DiceGame :JDBCKit :HighScoreJDBC

1:JDBCKit()

2:getInstance()
DiceGame sees JDBCKit as DBKit
and HighScoreJDBC as HighScore

3:DiceGame()
4:makeKit()
Only RealPlayer knows that
5:HighScoreJDBC() he uses JDBCKit, while
DiceGame does not!

6:load()

7:exit() 8:getInstance()

9:save()

OOAD
358
Case study

□ Deployment diagram

JDBC Connection

JDBC Computer

Game Computer

save/load the high score

Play the game


File System

OOAD
359
Main Activities of Software Development

Requirements
Analysis Design
Gathering
Design the solution /
Define requirement Define the conceptual model
software plan
specification

Implementation Integration and Test Deployment


Code the system based on Prove that the system meets
Installation and training
the design the requirements

Maintenance
Post-install review
Support docs
Active support

OOAD
360
Case study

□ Complete the interaction diagrams


□ Generate the code

OOAD
361

You might also like