15. Design Patterns
Programming Project 2021/22

15.2. What is a Design Pattern?

What is a design pattern?

"Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice"

Alexander et al. A Pattern Language: Towns, Buildings, Construction. Oxford University Press, 1977

What is a design pattern?

"A design pattern is a solution to a problem in a context"

Gang of Four. Design Patterns: Elements of Reusable Object-Oriented Software. 1994

Why design patterns?

  1. They are conceptual solutions for problems we recurrently encounter.
  2. They are formalized best practices.
  3. They help us to save time when thinking about possible solutions for a problem.
  4. They help us to increase the reusability and maintainability of our code.
  5. They contribute to bridge the quality gap in software design by experienced and novice developers.

How are design patterns described?

A design pattern has four essential elements.

  • Name is a brief handle we can use to describe a design problem, its solutions, and consequences.
    • It lets us design at a higher level of abstraction.
    • It makes it easier to think about designs and to communicate them and their trade-offs to others.
  • Problem describes when to apply the pattern.
    • It explains the problem and its context.
    • It might describe specific design problems or symptoms.
  • Solutions are the elements that make up the design, their relationships, responsibilities, and collaborations.
    • They do not necessarily describe a particular concrete design or implementation,
    • but provide a general arrangement of classes and objects to solve the problem.
  • Consequences are the results and trade-offs of applying the pattern.
    • They helps us to understand the costs and benefits of applying the pattern.
    • They are critical for evaluating and comparing design alternatives.