You are on page 1of 10

Chapter 18

Object Design Examples with GRASP


1 CS6359 Fall 2011 John Cole
Use Case Realization
Describes how a particular use case is realized
within the design model in terms of
collaborating objects

CS6359 Fall 2011 John Cole 2
Command-Query Separation
A method that changes the value of a variable
(or the state of the object) should not also
return (query) its value.
A method that returns the value of a variable
should not also change it.
CS6359 Fall 2011 John Cole 3
Connect UI to Domain
An initializer object creates both the UI and
the domain objects and passes the domain
object to the UI
The UI object retrieves the domain object
from a well-known source such as a factory
object that creates domain objects
CS6359 Fall 2011 John Cole 4
Basic Patterns
Creator
Information Expert
Controller
Low Coupling
High Cohesion

CS6359 Fall 2011 John Cole 5
Realization
Look at the objects suggested by the use case
Determine who should create them
Decide how they should interact
Determine which patterns are being used.

CS6359 Fall 2011 John Cole 6
Example: Sell Something
Register could create the Sale object
Sale object creates SalesLineItem objects in
list
SalesLineItem interacts with Product to get
pricing and description

CS6359 Fall 2011 John Cole 7
Design makeNewSale
Register creates Sale instance s and stores the
reference
Attributes of s are initialized

CS6359 Fall 2011 John Cole 8
Controller Class Design
Represents the overall system or root object
Store in the POS system is a root object
because other objects exist within it
POSSystem is also a root object
Register could also be a root object
CS6359 Fall 2012 John Cole 9
Creating a New Sale
Register creates a Sale object
Sale object, as part of its initialization, creates
an empty list of SalesLineItems
Register is, therefore, the Controller

CS6359 Fall 2011 John Cole 10

You might also like