---
title: "Pattern based design and benefits"
subject: "Object Oriented Analysis and Design"
chapter: 3
key: "semester_6/object_oriented_analysis_and_design:pattern-based-design-benefits"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/pattern-based-design-benefits
site: BCT Engineering
---

# Pattern based design and benefits

Object Oriented Analysis and Design · Chapter 3: Object Oriented Design

- Asked in: 2071 Magh, 7 marks
- Video: [What are Design Patterns? | Introduction to Design Patterns and Principles | Geekific](https://www.youtube.com/watch?v=mE3qTp1TEbg) — Geekific
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/pattern-based-design-benefits
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-3

## Question

What is pattern based design? What are the added benefits of using patterns? Prepare an illustrative note on pattern based design.

## Short answer

Pattern-based design applies named proven solutions (GoF, GRASP) to recurring problems instead of designing from scratch. Benefits include reuse of experience, common vocabulary, better quality (loose coupling, high cohesion), faster design, easier maintenance, and learning support. Example: Strategy for payment methods with Factory for creation and Singleton for gateway.

## Answer

#### Pattern based design
A **pattern** is a named and well-known description of a problem and its proven solution, with advice on how to apply it in new contexts. **Pattern-based design** means designing software by recognising recurring design problems and applying suitable patterns (GRASP for assigning responsibilities, GoF patterns like Factory, Singleton, Observer, Strategy) rather than designing everything from scratch.

Typical description of a pattern: **name, problem (context and forces), solution, consequences**. Example: *Problem:* who should create `OrderLine` objects? *Solution (Creator pattern):* assign the creation to the class that contains or closely uses them, here `Order`.

Categories: creational (Singleton, Factory), structural (Adapter, Facade, Composite), behavioural (Observer, Strategy, Command); and GRASP responsibility patterns.

```text
 Problem in a context
        |  recognise
        v
   Choose a pattern ---> Apply to own classes
        |                       |
        +-> check consequences -+--> Pattern-based design
```

#### Added benefits of using patterns
1. **Reuse of experience:** solutions already tested by many designers.
2. **Common vocabulary:** "use an Observer here" communicates a whole structure.
3. **Better design quality:** loose coupling, high cohesion, flexibility, extensibility.
4. **Faster design:** fewer design decisions from scratch, fewer mistakes.
5. **Easier maintenance and documentation:** other developers who know the patterns understand the design quickly.
6. **Supports learning:** helps beginners design like experts.
7. **Supports refactoring** to well-defined structures.

#### Illustrative note
For a payment module that must support card, e-wallet and bank transfer, a **Strategy** pattern is used: an interface `PaymentMethod` with `pay(amount)` and concrete classes `CardPayment`, `WalletPayment`. A new method is added by writing a new class, with no change in the checkout code. A **Factory** creates the correct object, and **Singleton** can provide the payment gateway connection.

**Caution:** patterns must not be used blindly; applying them where they are not needed adds complexity.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is pattern-based design?
   A. Designing only with diagrams
   B. Copying code from libraries
   C. Recognising recurring design problems and applying suitable named patterns instead of designing from scratch
   D. Designing screens only
   Answer: C. It means applying proven patterns to recurring problems. (Key point: Definition)

2. Which set describes a typical pattern description?
   A. Name, problem (context and forces), solution, consequences
   B. Author, date, size, price
   C. Input, output, process, storage
   D. Class, object, method, field
   Answer: A. A pattern is described by name, problem, solution and consequences. (Key point: Parts of a pattern)

3. In the payment example, why is Strategy used?
   A. To have only one payment object
   B. To create the gateway connection
   C. To add a new payment method by a new class without changing checkout code
   D. To store the bill
   Answer: C. Strategy lets implementations vary behind PaymentMethod, so new ones need no checkout changes. (Key point: Strategy example)

## Related in Object Oriented Analysis and Design

- [Pattern vs framework; GRASP patterns](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Apattern-vs-framework-grasp) — Object Oriented Analysis and Design, chapter 3
- [Short note: Design patterns in deployment](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Ashort-note-design-patterns-deployment) — Object Oriented Analysis and Design, chapter 3
- [Framework and design pattern with example](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aframework-design-pattern-example) — Object Oriented Analysis and Design, chapter 3

## Related in other subjects

- [Design patterns and their benefits](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Adesign-patterns) — Software Engineering, chapter 5
- [Benefits of computer based control](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acomputer-based-control-benefits) — Embedded System, chapter 7
- [Typical damage patterns in masonry buildings](https://www.bctengineer.com/question.md?key=semester_5%2Fdesign_of_timber_and_masonry_structures%3Adamage-patterns-masonry-lateral-loads) — Design of Timber and Masonry Structures, chapter 6
- [Flow patterns in plant layout](https://www.bctengineer.com/question.md?key=semester_6%2Findustrial_engineering_and_management%3Aflow-patterns-in-production-layout) — Industrial Engineering and Management, chapter 2
