GRASP 2 Flashcards
What problem does the Polymorphism pattern aim to resolve?
How to handle alternatives based on type?
Fundamental theme in programs
Adding new alternatives if using if-then-else or case-statement can require mods in many places
How to create pluggable software components?
E.g. Client-Server relationship:
o How to replace Server component without affecting Client?
What solution does the Polymorphism pattern propose?
When related alternatives vary by type (class):
use operations with the same interface
to assign responsibilities for the behaviour
to the types for which the behaviour varies.
Corollary:Don’t use conditionals to select the alternative.
Polymorphic: giving a single interface to entities of different types.
What are the contraindications of the Polymorphism pattern?
See contraindications for Protected Variations
What problem does the Pure Fabrication pattern aim to resolve?
Which object should have responsibility when solutions offered by (e.g.) Expert violate High Cohesion and Low Coupling?
Use domain objects in design to lower representational gap
Sometimes using only domain objects in design result in poor coupling, cohesion, or reuse
What solution does the Pure Fabrication pattern propose?
Assign a highly cohesive set of responsibilities to a class not in the problem domain:
Made up to support high cohesion, low coupling, and reuse.
Fabrication of the imagination, for the purpose of ensuring that the design is very pure
Name is also an English idiom for an intentional lie, something you do when desperate!
Pattern justifies increasing the representational gap.
What are the contraindications of the Pure Fabrication pattern?
Sometimes overused as excuse to add new objects
Can be driven by behavioural decomposition into functions, resulting in functions just being grouped into objects.
Needs to be balanced with representational decomposition: assigning responsibilities to classes that have the required information
Poorly applied, can adversely affect coupling
What problem does the Indirection pattern aim to resolve?
Where to assign a responsibility to avoid direct coupling between two (or more) s/w elements?
How to de-couple objects so that low coupling is supported and reuse potential remains higher?
What solution does the Indirection pattern propose?
Assign the responsibility to an intermediate object to mediate between the other components or services so that they are not directly coupled.
Intermediary creates an indirection between the other components.
What are the contraindications of the Indirection pattern?
Higher complexity in design needs to be justified by the lower coupling
Counter adage:
“Most problems in performance can be solved by removing another layer of indirection!”
What problem does the Protected Variations pattern aim to resolve?
How to design objects, subsystems, and systems so that the variations or instability in these elements does not have an undesirable impact on other elements?
Points of change include:
variation point: variations in existing system or requirements (e.g. multiple tax calculators)
evolution point: speculative variations that may arise in the future
What solution does the Protected Variations pattern propose?
Identify points of known or predicted variation or instability
Assign responsibilities to create a stable interface*around them
*Interface: a means of access (not only a programming language interface or Java interface)
What are the contraindications of the Protected Variations pattern?
Cost of speculative “future-proofing” at evolution points can outweigh the benefits
o It may be cheaper/easier to rework a simple “brittle” design
Novice designers tend toward brittle designs
Intermediate designers tend towards overly general and flexible designs (in ways not used)
Expert designers get the balance right
What is a pattern?
A pattern is a named problem/solution pair that can be applied in new context, with advice on how to apply it in novel situations and discussion of its trade-offs.