grasp 1
TRANSCRIPT
-
8/3/2019 Grasp 1
1/28
GRASP: A Learning Aid for OO
Design with Responsibilities
By
P.Vinitha
-
8/3/2019 Grasp 1
2/28
Objectives
GRASP: Designing objects with responsibilities
Creator
Information expert Low Coupling
Controller
High Cohesion
-
8/3/2019 Grasp 1
3/28
GRASP
General Responsibility Assignment Software
Patterns (or Principles), abbreviated GRASP,
consists of guidelines for assigning
responsibility to classes and objects in object-
oriented design
-
8/3/2019 Grasp 1
4/28
Object Design
What's been done?
Prior activities (e.g., workshop) and artifacts.
How do things relate? Influence of prior artifacts (e.g., use cases) on OO
design.
How much design modeling to do, and how?
What's the output?
-
8/3/2019 Grasp 1
5/28
What are Inputs to Object Design?
Scenarios
UML package diagrams
Supplementary specifications Glossary
Domain model
-
8/3/2019 Grasp 1
6/28
What are Inputs to Object Design?
The use case text defines the visible behavior that thesoftware objects must ultimately support to.
The Supplementary Specification defines the non-functional goals, such as internalization, our objects must
satisfy. The system sequence diagrams identify the system
operation messages.
The Glossary clarifies details of parameters or data comingin from the UI layer, data being passed to the database etc..
The Domain Model suggests some names and attributes ofsoftware domain objects in the domain layer of thesoftware architecture.
-
8/3/2019 Grasp 1
7/28
What are Activities of Object Design?
Given one or more of these inputs, developers
1. Start immediately coding (ideally with test-first
development)
2. Start some UML modeling for the object design,
or
3. Start with another modeling technique, such as
CRC cards
-
8/3/2019 Grasp 1
8/28
What are Activities of Object Design?
UMLs purpose is to visualize modeling using a
language that allows us to explore more
visually than we can with just raw text.
The approach is to use a Responsibility-driven
Design (RDD), thinking about how to assign
responsibilities to collaborating objects
-
8/3/2019 Grasp 1
9/28
What Are the Outputs?
UML interaction, class, and package diagrams
for the difficult parts of the design that we
wished to explore before coding
UI sketches and prototypes
Database models
Report sketches and prototypes
-
8/3/2019 Grasp 1
10/28
Responsibilities and Responsibility-
Driven Design
Responsibility Driven Design or RDD is apopular way of thinking about the design ofsoftware objects and also larger-scale
components in terms of Responsibilities
Roles
Collaborations
Software objects responsibilities Abstraction of what they do
-
8/3/2019 Grasp 1
11/28
Responsibility
The UML defines a Responsibility as "a
contract or obligation of a classifier.
Responsibilities are related to the obligationsor behavior of an object in terms of its role.
Types of responsibilities
Doing
Knowing.
-
8/3/2019 Grasp 1
12/28
Doing responsibilities
Doing responsibilities of an object include:
Doing something itself, such as creating an object
or doing a calculation
Initiating action in other objects
Controlling and coordinating activities in other
objects
-
8/3/2019 Grasp 1
13/28
Knowing responsibilities
Knowing responsibilities of an object
include:
knowing about private encapsulated data knowing about related objects
knowing about things it can derive or
calculate
-
8/3/2019 Grasp 1
14/28
Responsibilities
Responsibilities are assigned to classes of objectsduring object design. For example, We may declare that "a Sale is
responsible for creating SalesLineItems" (a doing), or"a Sale is responsible for knowing its total" (aknowing).
The translation of responsibilities into classes andmethods is influenced by the granularity of the
responsibility. Big responsibilities take hundreds of classes and
methods
-
8/3/2019 Grasp 1
15/28
Responsibilities
Responsibilities are implemented by means of
methods that either act alone or collaborate
with other methods and objects.
For example, the Sale class might define one or
more methods to know its total; say, a method
named getTotal. To fulfill that responsibility, the
Sale may collaborate with other objects, such assending a getSubtotal message to each
SalesLineItem object
-
8/3/2019 Grasp 1
16/28
GRASP principles
The GRASP principles or patterns are a
learning aid to help you understand essential
object design and apply design reasoning in a
methodical, rational, explainable way.
This approach to understanding and using
design principles is based on patterns of
assigning responsibilities
-
8/3/2019 Grasp 1
17/28
GRASP principles
Design pattern is a proven solution to some
common problems that we face with when
developing the application architecture.
These solutions are intended to make the
application better more extensible, flexible,
simple.
-
8/3/2019 Grasp 1
18/28
Common examples of design problems
Organizing access to the shared resource. This can beapplication object, DB abstraction object, Sessionobject or other similar things..
Creating the easily extensible application. For example,code shopping cart in the way, that allows to add newpayment or taxation modules easily.
Providing the simple interface for accessing features ofthe application or application module, hiding all theunderlying classes/functions from the user.
Separating data from data processing and frompresentation. Eg :MVC (Model-View-Controller
-
8/3/2019 Grasp 1
19/28
Connection Between Responsibilities,
GRASP, and UML Diagrams
We can assign responsibilities to objects while
coding or while modeling.
Within the UML, drawing interaction diagramsbecomes the occasion for considering these
responsibilities (realized as methods).
-
8/3/2019 Grasp 1
20/28
Connection Between Responsibilities,
GRASP, and UML Diagrams
Sale objects have been given a responsibility to create Payments, which is
concretely invoked with a makePayment message and handled with a
corresponding makePayment method.
-
8/3/2019 Grasp 1
21/28
Patterns
In OO design, a pattern is a named description
of a problem and solution that can be applied
to new contexts.
A pattern advises us on how to apply its
solution in varying circumstances and
considers the forces and trade-offs.
Patterns guide the assignment of
responsibilities to objects.
-
8/3/2019 Grasp 1
22/28
Patterns
Example :
Pattern Name: Information Expert
Problem: What is a basic principle by which to
assign responsibilities to objects?
Solution: Assign a responsibility to the class that
has the information needed to fulfill it.
-
8/3/2019 Grasp 1
23/28
Patterns
Patterns themselves are implementation of the 9basic principles. Creator
Information Expert Low Coupling
High Cohesion
Controller
Polymorphism
Pure Fabrication
Indirection
Protected Variations
-
8/3/2019 Grasp 1
24/28
Patterns
A good pattern is
A named and well-known problem/solution pair
Can be applied in new contexts, with advice on
how to apply it in novel situations
Discussion of its trade-offs, implementations,
variations, and so forth.
-
8/3/2019 Grasp 1
25/28
Patterns
Patterns Have Names : Important
Naming a pattern, design idea, or principle has the
following advantages:
It supports chunking and incorporating that concept
into our understanding and memory.
It facilitates communication.
Example: Information Expert and Abstract Factory
-
8/3/2019 Grasp 1
26/28
Creator
The most common problem in OO design is Whoshould create object X?
This principle states, that object A should create
object B if: A contains or aggregates B (e.g. Object User should
initialize object Address)
A records B (saves to DB or file)
A closely uses B A has the initialization data that should be passed to B
when object is created
-
8/3/2019 Grasp 1
27/28
Creator
Example
In the NextGen POS
application, who should be
responsible for creating aSalesLineItem instance?
By Creator, we should look
for a class that aggregates,
contains, and so on,SalesLineItem instances
-
8/3/2019 Grasp 1
28/28
Creator
Since a Sale contains (in fact, aggregates) many SalesLineItem
objects, the Creator pattern suggests that Sale is a good
candidate to have the responsibility of creating SalesLineItem
instances.
This leads to the design of object interactions shown in Figure
This assignment of responsibilities requires
that a makeLineItem method be defined in
Sale.