What Is A Design Pattern
- Sort of customizable blueprints
- You cant directly copy and embedded into your code. The pattern represents a conceptual way to solve a given problem
- An algorithm is also a conceptual solution. However, desing pattern is a more abstracted higher-level description of a solution.
- The code for the same pattern for two different applications may be different
- An algorithm is a receipe whereas a patterns is more like a blueprint
- What includes a pattern
- Intent ⇒ describing the problem and the solution
- Motivation ⇒ elaborates in detail the need for the pattern
- Structure (of classes) ⇒ shows each part of the pattern and how they are related
- Code example ⇒ makes it easier to grasp the idea
Why To Learn
- You could get away many years programming without a single pattern
- You may be implementing these patterns without realizing it
- Design patterns are a toolkit of tried and tested solutions that solve common problem in software design. They teach how to solve all sort of recurrent SWE problems via an OOP approach.
- They define a common/standarized language for communicating ideas behind a given problem
Criticism of patterns
- Too rigid implementation. Not customized enough
- Unjustified use: if you have a hammer, everything looks like a nail
History, Origins