Oose_week 10 - Grasp Pattern i
-
Upload
innoxentdoll -
Category
Documents
-
view
217 -
download
0
Transcript of Oose_week 10 - Grasp Pattern i
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 1/24
GRASP PatternGRASP Pattern
Object Oriented Software
Engineering
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 2/24
OutlineOutline
Introduction
Creator
Information Expert
GRASP Patterns 2
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 3/24
IntroductionIntroduction
Design process
!at"s GRASP pattern
!at"s responsibi#it$
Responsibi#ities and met!ods
Responsibi#ities and Interaction Diagrams
GRASP Patterns %
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 4/24
Design ProcessDesign Process
After identif$ing $our re&uirements and
creating a domain mode#' t!en add met!ods
to t!e software c#asses' and define t!emessaging between t!e objects to fu#fi## t!e
re&uirements(
GRASP Patterns )
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 5/24
What is Pattern?What is Pattern? * It is common t!at w!en experts wor+s on particu#ar prob#ems' t!e$ need not
rein,ent t!e w!ee# i(e( t!e$ need not find a comp#ete new so#ution t!at is
comp#ete#$ different from existing so#utions( Rat!er t!e$ remember t!e
simi#ar prob#em and it so#ution and reuse t!e core of it for so#,ing new
prob#em( -!e$ t!in+ in terms of .Problem Solution/ pairs( Abstracting
from suc! pairs and c!urning out t!e commona#ities #eads to patterns(
* Eac! pattern is t!ree0part ru#e w!ic! expresses a re#ation between a certain
context' a prob#em and a so#ution(
* Patterns !a,e names and t!e$ faci#itate communication0 common,ocabu#ar$ and understanding0eas$ to remember w!o#e concept in a
nuts!e##
GRASP Patterns 1
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 6/24
GGeneraleneral RResponsibilityesponsibility
AAssignmentssignment SSoftwareoftware PPatternsatterns
Craig arman coined t!ese terms for t!e first time(
Stands for
Genera# R esponsibi#it$ Assignment Software Patterns(-!e mnemonic meaning cou#d be .successfu# OOAD
3Object Oriented Ana#$sis 4 Design5 re&uires grasping
3understanding5/(
GRASP Patterns 6
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 7/24
GRASPGRASP
GRASP Patterns 7
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 8/24
Whats GRASP patternWhats GRASP pattern
-!is approac! to understanding and using
design princip#es is based on patterns of
assigning responsibi#ities(
-!e GRASP patterns are a #earning aid to
!e#p one understand essentia# object design'and app#$ design reasoning in a met!odica#'
rationa#' exp#ainab#e wa$(
GRASP Patterns 8
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 9/24
Whats responsibilityWhats responsibility
Doing9
* Doing somet!ing itse#f' suc! as creating an object or
doing a ca#cu#ation * Initiating action in ot!er objects
* Contro##ing and coordinating acti,ities in ot!er objects(
:nowing9
* :nowing about pri,ate encapsu#ated data
* :nowing about re#ated objects
* :nowing about t!ings it can deri,e or ca#cu#ate
GRASP Patterns ;
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 10/24
Responsibilities and methodsResponsibilities and methods
9Sa#e
9Pa$ment
ma+ePa$mentcreate
ma+ePa$ment imp#ies Sa#e object !as a responsibi#it$ to
create a Pa$ment objectGRASP Patterns <=
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 11/24
Responsibilities andResponsibilities and
Interaction DiagramsInteraction DiagramsInteraction diagrams s!ow c!oices in
assigning responsibi#ities to objects(
GRASP patterns guide c!oices in w!ere to
assign responsibi#ities(
GRASP patterns are a codification of
wide#$ used basic princip#es(
GRASP Patterns <<
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 12/24
GRASP PatternsGRASP Patterns
; GRASP patterns
Creator
Information Expert
ow Coup#ing
Contro##er
>ig! Co!esion
Indirection
Po#$morp!ism
Protected ?ariations
Pure @abrication
GRASP Patterns <2
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 13/24
!reator !reator
Problem:Problem: !o is responsib#e for creating new instances of somec#ass
Solution:Solution: Assign c#ass B t!e responsibi#it$ to create an instance ofc#ass A if one or more of t!e fo##owing is true9
B aggregates A 3simp#e aggregate s!ared attributes5
B contains A 3composition non0s!ared attributes5
B records instances of A objects
B closely uses A objects
B has the initializing data t!at wi## be passed to A
w!en it is created 3t!us B is an Expert wit! respect to
creating A5 If more t!an one option app#ies' prefer a c#ass B w!ic! aggregates orcontains c#ass A(
GRASP Patterns <%
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 14/24
!reator !reator
Consider abo,e examp#e' sa#e wi## contain man$ Sa#esineItem
objects( Creator GRASP pattern suggests Sa#e is one object t!at
cou#d fu#fi## t!is responsibi#it$(GRASP Patterns <)
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 15/24
"#ample for !reator "#ample for !reator
Consider ?ideoStore and ?ideo in t!at store(
?ideoStore !as an aggregation association
wit! ?ideo(
i(e' ?ideoStore is t!e container and t!e ?ideo is t!e
contained object(
So' we can instantiate ,ideo object in ?ideoStorec#ass
GRASP Patterns <1
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 16/24
"#ample of !reator "#ample of !reator
GRASP Patterns <6
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 17/24
Information "#pertInformation "#pert
Problem:!at is a genera# princip#e of assigning responsibi#ities
to objects
* !o s!ou#d be responsib#e for +nowingdoing
* Domain mode# 3domain expert' domain ana#$sis5 to designmode# 3software c#asses5(
Solution:
Assign a responsibi#it$ to t!e information expert
* t!e c#ass t!at !as t!e information necessar$ to fu#fi## t!e
responsibi#it$(
GRASP Patterns <7
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 18/24
Information "#pertInformation "#pert
Question
Do we #oo+ at t!e Domain Fode# or t!e Design Fode# to ana#$e t!e c#asses
t!at !a,e t!e information needed
Domain model illustrates conceptual classes, design model software classesAnswer
<( If t!ere are re#e,ant c#asses in t!e Design Fode#' #oo+ t!ere first(
2( Ot!erwise' #oo+ in t!e Domain Fode#' and attempt to use 3or expand5 its
representations to inspire t!e creation of corresponding design c#asses(
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 19/24
Example on applyingExample on applying
Start b$ c#ear#$ stating t!e responsibi#it$9
.!o s!ou#d be responsib#e for +nowing t!e tota# of a sa#e
App#$ .Information Expert/ pattern
Assume we are just starting design wor+ and t!ere is no or a
minima# Design Fode#' t!erefore
* Searc! t!e Domain Fode# for information experts t!e
rea#0wor#d Sa#e is a good candidate(
-!en' add a software c#ass to t!e Design Fode# simi#ar#$
ca##ed Sale, and give it the responsibility of knowing its tota#'
expressed wit! t!e met!od named getTotal.
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 20/24
"#ample$ What information is"#ample$ What information is
needed to determine the grand total?needed to determine the grand total?
Sa#e
date
Product
description
price
itemID
GRASP Patterns 2=
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 21/24
Sa#e
date
Product
description
price
itemID
Sa#esineItem
&uantit$
!o is information expert
GRASP Patterns 2<
"#ample !ontd"#ample !ontd
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 22/24
Sa#e
date
Product
description
priceitemID
Sa#esineItem
&uantit$
get-ota#
getSub-ota#
getPrice
GRASP Patterns 22
"#ample !ontd"#ample !ontd
7/26/2019 Oose_week 10 - Grasp Pattern i
http://slidepdf.com/reader/full/ooseweek-10-grasp-pattern-i 23/24
"#ample %"#ample %
Assume we need to get a## t!e ,ideos of a ?ideoStore(
Since ?ideoStore +nows about a## t!e ,ideos' we canassign t!is responsibi#it$ of gi,ing a## t!e ,ideos can
be assigned to ?ideoStore c#ass(
?ideoStore is t!e information expert(