09-grasp

09-grasp - CS4240 PrinciplesofSoftwareDesign AaronBloomfield

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style CS 4240 Principles of Software Design Aaron Bloomfield GRASP Fall 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Click to edit Master subtitle style 22 GRASP General Responsibility Assignment  Software Patterns (they are more of principles, really)
Background image of page 2
33 GRASP patterns n There are nine: 1. Creator 2. Information Expert 3. Low Coupling 4. Controller 5. High Cohesion 6. Polymorphism 7. Pure Fabrication Indirection
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
44 Creator n Name n Problem n Solution n Creator n Who creates an A? n Assign  class  B  the  responsibility  to  create  an A if one or more are true: n B “contains” or compositely aggregates A n B records A n B closely uses A
Background image of page 4
55 Information Expert n Name n Problem n Solution n Information expert n What is a basic principle by which to assign  responsibilities to objects? n Assign a responsibility to the class that has  the information needed to fulfill it
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
66 Information Expert, continued Sale time ... getTotal() SalesLineItem quantity getSubtotal() Product Description description price itemID getPrice() New method :Product Description 1.1: p := getPrice() 1 *: st = getSubtotal : Sale t = getTotal lineItems[ i ] : SalesLineItem
Background image of page 6
77 Low Coupling n Name n Problem n Solution n Low coupling n How to reduce the impact of change? n Assign  responsibilities  so  that  (unnecessary)  coupling  remains  low.    Use  this principle to evaluate alternatives
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Low coupling, continued : Register p : Payment :Sale makePayment() 1: create() 2: addPayment(p) : Register :Sale :Payment makePayment() 1: makePayment() 1.1. create()
Background image of page 8
99 Controller n Name n Problem n Solution n Controller n What  first  objects  beyond  the  UI  layer  receives  and  coordinates  (“controls”)  a  system operation? n Assign  the  responsibilities  to  an  object  representing one of these choices: n Represents  the  overall  “system”,  major subsystem, etc. n Represents a use case scenario within which the
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Controller, continued Which class of object should be responsible for receiving this system event message? It is sometimes called the controller or coordinator. It does not normally do the work, but delegates it to other objects. The controller is a kind of "facade" onto the domain layer from the interface layer. actionPerformed( actionEvent ) : ??? : Cashier :SaleJFrame presses button enterItem(itemID, qty) UI Layer Domain Layer system operation message
Background image of page 10
1111 High Cohesion n Name n Problem n Solution n High cohesion n How  to  keep  objects  focused,  understandable, and manageable, and as a  side effect, support low coupling? n Assign  responsibilities  so  that  cohesion  remains  high.    Use  this  to  evaluate alternatives.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Click to edit Master subtitle style 1212 Applying GRASP principles
Background image of page 12
1313 Context n The 4 operation contracts from the POS system n makeNewSale() n enterItem() n endSale() n makePayment() n These examples are overkilled n It’s the application of the principles that is important
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1414
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 60

09-grasp - CS4240 PrinciplesofSoftwareDesign AaronBloomfield

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online