Design Patterns
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
How to use a design patterns
- Find the problem
- Find the generic pattern for this problem
- Create his own solution by reusing the generic solution
Identify the problem
It is necessary to understand well his conception problem. In other case, the choosen pattern can fit bad with the problem, and can make more problems than it resolves.
The knowledge of the different existing patterns can help: most of the time, the problems are the same. Some problems are more complex than the other, have been confronted to the problem allows to recognize it more fast.
Find the pattern
When the problem is clearly identified, we have to find if he correspond to the problem targeted by one of the patterns, and if the purpose of the pattern correspond (sometimes, two patterns are very close, but their purpose are very different, and they should not be mingled). Then, we have to identify the different participants. Finally, we have to verify if the negative concequencies of this pattern are not crippling.
Apply the pattern
Then, we have to create our own solution by reusing the generic solution. We match our participants and pattern's ones, and we recreate the pattern schematic with our own names. We can adapt the names to the domain (the patterns don't enforce naming, associations or opperation), but sometime it can be good to let the pattern suffix to make it more readable. For instance, rename the class WidgetGenerator
into WidgetFactory
can express more clearly the pattern used.