Software Design Patterns I
Software Design Patterns I
Introduction
Designing object-oriented software is hard, and designing one to standards is ever harder. Designs should be granular enough for the problem and general enough to handle future problems. Design can never be correct the first time.
Design Patterns
"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 - Christopher Alexander
Design Patterns
Although Alexander was talking about design solutions or patterns for towns and buildings, the same principles are applied to out software and any kind of problem. There are four key parts of a design pattern namely pattern name, problem, solution, and consequences.
Pattern Name
Naming conventions for patterns allow us to easily communicate these solutions with our colleagues. It becomes easier to refer to them in documentation and it allows us to design them in a higher level of abstraction.
Problem
The problem describes the reason why we have the design solution in the first place. The problem also includes the unique context that its in.
Solution
The solution describes the different aspects of the design pattern including the elements and their relationships, interactions, responsibilities and collaborations. The only thing that a solution does not describe is the concrete, specific implementation of it. Instead it serves as a template showing you how to solve it.
Consequences
These are obviously trade-offs of applying the design and are often critical when we want to evaluate design decision that were made along the way. They are very important when we want to evaluate other alternatives, and understanding the cost and benefits of a certain pattern implementation.
They are descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.
Structural
They are concerned with the composition of objects
Behavioural
They are concerned with the way objects and classes interact and distribute responsibility.