- 2072 Asoj · 8 marks
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
| Point | Pattern | Framework |
|---|---|---|
| Nature | An idea: description of a problem and its solution | Actual code: reusable classes and libraries |
| Level | Abstract, design level | Concrete, implementation level |
| Size | Small, solves one design problem | Large, a whole application skeleton |
| Use | You implement it yourself in any language | You extend or plug into it |
| Control | Your code stays in control | The framework calls your code (inversion of control) |
| Example | Observer, Singleton, Factory | Spring, 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?Saleknows itsSalesLineItems, soSale.getTotal(); each line item knows its quantity and price, soSalesLineItem.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:
SalecontainsSalesLineItems, soSalecreates 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
Registercreates thePaymentand passes it toSale, thenRegisteris coupled to bothSaleandPayment. IfSalecreates thePaymentitself,Registerdoes not need to knowPayment, 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
Related questions
- Framework and design pattern with example · Object Oriented Analysis and Design, chapter 3
- Pattern based design and benefits · Object Oriented Analysis and Design, chapter 3
- Short note: Design patterns in deployment · Object Oriented Analysis and Design, chapter 3
- Short note: GRASP · Object Oriented Analysis and Design, chapter 3
- Knowledge management vs expert systems · Information System, chapter 4
- Design patterns and their benefits · Software Engineering, chapter 5
- Typical damage patterns in masonry buildings · Design of Timber and Masonry Structures, chapter 6
- Reuse framework versus program generator · Software Engineering, chapter 5
All Object Oriented Analysis and Design chapter 3 questions →