More GRASP Patterns: Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee
More GRASP Patterns: Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee
Chapter 22
Applying UML and Patterns
Craig Larman
Prepared By: Krishnendu Banerjee
NJIT
Objectives
Learn to apply the following GRASP
patterns:
Polymorphism
Pure Fabrication
Indirection
Protected Variations
Introduction
GRASP stands for General Responsibility
Assignment Software Patterns.
It is a learning aid of fundamental principles
by which responsibilities are assigned to
objects and objects are designed.
We already learned about the first five
GRASP patterns:
Information Expert, Creator, High Cohesion,
Low Coupling, Controller
Introduction
In this presentation we will look at four
new GRASP patterns:
Polymorphism
Indirection
Pure Fabrication
Protected Variations
Polymorphism
Problem
Who is responsible when behaviors vary by
type?
How to handle alternatives based on type?
How to create pluggable software
components?
Polymorphism
Solution
Polymorphism is a fundamental principle in
designing how a system is organized to handle
similar variations.
Solution
Identify points of predicted variation or instability;
assign responsibilities to create a stable interface
around them.
Protected Variations
PV is the root principle motivating most of
the mechanism and patterns in
programming and design to provide
flexibility and protection from variation.
Service Lookup
JNDI, LDAP, Java’s Jini, UDDI.
Protected Variations:
Mechanisms
Interpreter Driven Design
Rule interpreters, virtual machines, neural
network engines, logic engines.
Reflective of Meta-level Design
Java introspector
Uniform Access
Language supported constructs that do not
change with change in underlying
implementation.
Protected Variations:
Mechanisms
The Liskov Substitution Principle (LSP)
Software methods that work with a class T
should work with all subclasses of T.
Structure-Hiding Design
Places constraints on what object you should
send messages to within a method.
Protected Variations:
Example
In the external tax calculator problem, the
point of instability is the different interfaces
to the external tax calculators.
By adding a level of indirection, an
interface, and using polymorphism with
various adaptors, protection within the
system from variations in external
calculator APIs is achieved.
Protected Variations:
Contraindications
The cost of speculative “future-proofing” at
evolution point may outweigh the cost
incurred by a simple design that is
reworked as necessary. Evolution point is
a speculative point of variation that may
arise in future, but not specified in current
requirement.
Protected Variations:
Benefits
Extensions required for new variations are
easy to add.
New implementations can be introduced
without affecting clients.
Coupling is lowered.
The impact or cost of changes be lowered.