Design patterns are lessons learnt over the years. A pattern is a solution to the recurring problems. Every pattern has four parts:
- Name: It is the common vocabulary. By using a name, we can describe a problem, its solution, and consequences.
- Problem: It tells us when to apply the pattern.
- Solution: It shows us how the problem is resolved.
- Consequences: It shows us the results and trade-offs of applying the pattern. This is the most important part of a pattern, and is critical for making the design decision. For example, if a problem can be solved using either pattern A or pattern B, how would you select the one you need? Read the consequences of applying pattern A and B and then choose the one that suits your need.