Skip to main content

Pattern vs framework; GRASP patterns

Short answer

A pattern is an abstract solution idea, while a framework is a reusable code skeleton. In GRASP, Information Expert assigns responsibility to the class with the needed data, Creator gives creation to the containing class, and Low Coupling minimizes dependencies to ease change.

How pattern different from framework? Explain information Expert, Creator and Low Coupling design patterns defined by GRASP Design Pattern.

Pattern vs framework

PointPatternFramework
NatureAn idea: description of a problem and its solutionActual code: reusable classes and libraries
LevelAbstract, design levelConcrete, implementation level
SizeSmall, solves one design problemLarge, a whole application skeleton
UseYou implement it yourself in any languageYou extend or plug into it
ControlYour code stays in controlThe framework calls your code (inversion of control)
ExampleObserver, Singleton, FactorySpring, Struts, Swing

A framework often uses several patterns. Patterns are more general and smaller architectural elements than frameworks.

GRASP patterns

GRASP (General Responsibility Assignment Software Patterns, by Larman) guides the assignment of responsibilities to classes.

1. Information Expert

  • Problem: what is the basic principle for assigning a responsibility?
  • Solution: assign it to the class that has the information needed to fulfil it.
  • Example: who computes the total of a Sale? Sale knows its SalesLineItems, so Sale.getTotal(); each line item knows its quantity and price, so SalesLineItem.getSubtotal().
  • Benefit: encapsulation, low coupling, high cohesion.

2. Creator

  • Problem: who should create an instance of class A?
  • Solution: assign the creation of A to B if B aggregates or contains A, records A, closely uses A, or has the initialising data for A.
  • Example: Sale contains SalesLineItems, so Sale creates them (Sale.makeLineItem()).
 Sale ---<>--- SalesLineItem
 Sale creates SalesLineItem

3. Low Coupling

  • Problem: how to reduce the impact of change and increase reuse?
  • Solution: assign responsibilities so that coupling (dependency between classes) stays low. Choose the design with fewer dependencies.
  • Example: if Register creates the Payment and passes it to Sale, then Register is coupled to both Sale and Payment. If Sale creates the Payment itself, Register does not need to know Payment, so there is one less dependency and the coupling is lower.
  • Benefit: classes are independent, and easier to understand, change and reuse.

✓ Answer checked by Claude Sonnet 5.5

All Object Oriented Analysis and Design chapter 3 questions →