GRASP GRASP GRASP an acronym that stands for

  • Slides: 8
Download presentation
GRASP

GRASP

GRASP • GRASP: an acronym that stands for General Responsibility Assignment Software Patterns •

GRASP • GRASP: an acronym that stands for General Responsibility Assignment Software Patterns • I think a RAP is a better acronym. – Do the words general & software pull their weight? 2

The 9 GRASP • Information Expert – Information expert: the class that has the

The 9 GRASP • Information Expert – Information expert: the class that has the information necessary to fulfill the responsibility. – Assign a responsibility to the information expert. • Creator – Who creates instances of class A? – Class B when: • B has A[s] • B is an information expert for A (has the constructor arguments). 3

The 9 GRASP … • Controller Who handles a system event? The system’s façade

The 9 GRASP … • Controller Who handles a system event? The system’s façade [controller] class. • Low coupling Minimize inter-class coupling • High cohesion Maximize intra-class cohesion 4

The 9 GRASP: Polymorphism To vary a general behavior by class: – Extend a

The 9 GRASP: Polymorphism To vary a general behavior by class: – Extend a base class – Implement an interface Example: Command pattern. • The Lectures page has Service. Impl. java • Jicos has around 60 different Commands 5

The 9 GRASP: Pure Fabrication Assign a highly cohesive set of responsibilities to a

The 9 GRASP: Pure Fabrication Assign a highly cohesive set of responsibilities to a class that is: – Created to support OOD: • High cohesion • Low coupling – Examples • Façade, adaptor, & bridge patterns are pure fabrications that lower coupling 6

The 9 GRASP: Indirection Mediate: 1. Acting through an intervening agent. 2. To interpose

The 9 GRASP: Indirection Mediate: 1. Acting through an intervening agent. 2. To interpose between parties, esp. to effect an agreement; as, to mediate between nations. Client Mediator A client/service mediator class. – Lowers coupling Service – Examples: Façade, Adaptor, Bridge (Sound familiar? ) 7

The 9 GRASP: Protected Variations • Define a stable interface to hide an area

The 9 GRASP: Protected Variations • Define a stable interface to hide an area of instability. Yes: List list = new Array. List(); // java. util. List not java. awt. List No: Array. List list = new Array. List(); Yes: for ( Iterator i = c. iterator(); i. has. Next(); ) { do. Something( i. next() ); } Yes: Java List, Map interfaces. 8