Skip to main content

Pattern based design and benefits

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.

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

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.

 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.

All Object Oriented Analysis and Design chapter 3 questions →