0% found this document useful (0 votes)
337 views24 pages

Oose - Week 10 - Grasp Pattern I

The document discusses the GRASP (General Responsibility Assignment Software Patterns) patterns. It introduces the Creator and Information Expert patterns. The Creator pattern suggests assigning the responsibility of creating an object to the class that aggregates or contains that object. The Information Expert pattern suggests assigning a responsibility to the class that has the necessary information to fulfill that responsibility. Examples are provided to illustrate applying both patterns, such as assigning the responsibility of calculating a sale's total to the Sale class.

Uploaded by

InnoxentDoll
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
337 views24 pages

Oose - Week 10 - Grasp Pattern I

The document discusses the GRASP (General Responsibility Assignment Software Patterns) patterns. It introduces the Creator and Information Expert patterns. The Creator pattern suggests assigning the responsibility of creating an object to the class that aggregates or contains that object. The Information Expert pattern suggests assigning a responsibility to the class that has the necessary information to fulfill that responsibility. Examples are provided to illustrate applying both patterns, such as assigning the responsibility of calculating a sale's total to the Sale class.

Uploaded by

InnoxentDoll
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Object Oriented Software

Engineering

GRASP Pattern

Outline
Introduction
Creator
Information

Expert

GRASP Patterns

Introduction
Design

process
Whats GRASP pattern
Whats responsibility
Responsibilities and methods
Responsibilities and Interaction Diagrams

GRASP Patterns

Design Process
After

identifying your requirements and


creating a domain model, then add methods
to the software classes, and define the
messaging between the objects to fulfill the
requirements.

GRASP Patterns

What is Pattern?
It is common that when experts works on particular problems, they need not

reinvent the wheel i.e. they need not find a complete new solution that is
completely different from existing solutions. Rather they remember the
similar problem and it solution and reuse the core of it for solving new
problem. They think in terms of Problem Solution pairs. Abstracting
from such pairs and churning out the commonalities leads to patterns.
Each pattern is three-part rule which expresses a relation between a certain

context, a problem and a solution.


Patterns have names and they facilitate communication- common

vocabulary and understanding-easy to remember whole concept in a


nutshell

GRASP Patterns

General Responsibility
Assignment Software Patterns
Craig

Larman coined these terms for the first time.


Stands for
General Responsibility Assignment Software Patterns.
The mnemonic meaning could be successful OOAD
(Object Oriented Analysis & Design) requires grasping
(understanding).

GRASP Patterns

GRASP

GRASP Patterns

Whats GRASP pattern


This

approach to understanding and using


design principles is based on patterns of
assigning responsibilities.

The

GRASP patterns are a learning aid to


help one understand essential object design,
and apply design reasoning in a methodical,
rational, explainable way.
GRASP Patterns

Whats responsibility
Doing:
Doing something itself, such as creating an object or

doing a calculation
Initiating action in other objects
Controlling and coordinating activities in other objects.
Knowing:
Knowing about private encapsulated data
Knowing about related objects
Knowing about things it can derive or calculate
GRASP Patterns

Responsibilities and methods


:Sale
makePayment

create
:Payment

makePayment implies Sale object has a responsibility to


create a Payment object
GRASP Patterns

10

Responsibilities and
Interaction Diagrams
Interaction

diagrams show choices in


assigning responsibilities to objects.
GRASP patterns guide choices in where to
assign responsibilities.
GRASP patterns are a codification of
widely used basic principles.

GRASP Patterns

11

GRASP Patterns
9 GRASP patterns
Creator
Information Expert
Low Coupling
Controller
High Cohesion
Indirection
Polymorphism
Protected Variations
Pure Fabrication
GRASP Patterns

12

Creator
Problem: Who is responsible for creating new instances of some
class?
Solution: Assign class B the responsibility to create an instance of
class A if one or more of the following is true:
B aggregates A (simple aggregate; shared attributes)
B contains A (composition; non-shared attributes)
B records instances of A objects
B closely uses A objects
B has the initializing data that will be passed to A
when it is created (thus B is an Expert with respect to
creating A)
If more than one option applies, prefer a class B which aggregates or
contains class A.

GRASP Patterns

13

Creator

Consider above example, sale will contain many SalesLineItem


objects. Creator GRASP pattern suggests Sale is one object that
GRASP Patterns
14
could fulfill this responsibility.

Example for Creator


Consider VideoStore and Video in that store.
VideoStore has an aggregation association
with Video.
i.e, VideoStore is the container and the Video is the
contained object.
So,

we can instantiate video object in VideoStore


class

GRASP Patterns

15

Example of Creator

GRASP Patterns

16

Information Expert
Problem:
What is a general principle of assigning responsibilities
to objects?
Who should be responsible for knowing/doing ?
Domain model (domain expert, domain analysis) to design

model (software classes).

Solution:
Assign a responsibility to the information expert
the class that has the information necessary to fulfill the

responsibility.

GRASP Patterns

17

Information Expert
Question
Do we look at the Domain Model or the Design Model to analyze the classes
that have the information needed?
Domain model illustrates conceptual classes, design model software classes
Answer
1. If there are relevant classes in the Design Model, look there first.
2. Otherwise, look in the Domain Model, and attempt to use (or expand) its
representations to inspire the creation of corresponding design classes.

Example on applying
Start by clearly stating the responsibility:
Who should be responsible for knowing the total of a sale?
Apply Information Expert pattern
Assume we are just starting design work and there is no or a
minimal Design Model, therefore

Search the Domain Model for information experts; the

real-world Sale is a good candidate.


Then, add a software class to the Design Model similarly
called Sale, and give it the responsibility of knowing its total,
expressed with the method named getTotal.

Example: What information is


needed to determine the grand total?
Sale

Product

date

description
price
itemID

GRASP Patterns

20

Example Contd
Sale
date

Product

SalesLineItem

description
price
itemID

quantity

Who is information expert?


GRASP Patterns

21

Sale

Example Contd

date
getTotal

Product

SalesLineItem

description
price
itemID

quantity
getSubTotal

getPrice
GRASP Patterns

22

Example 2
Assume

we need to get all the videos of a VideoStore.

Since

VideoStore knows about all the videos, we can


assign this responsibility of giving all the videos can
be assigned to VideoStore class.

VideoStore

is the information expert.

Example 2 contd

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy