Chapter 5. Writing Design Patterns
Although this book is aimed at those new to design patterns, a fundamental understanding of how a design pattern is written can offer a number of useful benefits. For starters, we can gain a deeper appreciation for the reasoning behind why a pattern is needed. We can also learn how to tell if a pattern (or proto-pattern) is up to scratch when reviewing it for our own needs.
Writing good patterns is a challenging task. Patterns not only need to (ideally) provide a substantial quantity of reference material for end users, but they also need to be able to defend why they are necessary.
Having read the previous section on what a pattern is, we may think that this in itself is enough to help us identify patterns we see in the wild. This is actually not completely true. It’s not always clear if a piece of code we’re looking at is following a set pattern or just accidentally happens to appear like it does.
When we’re looking at a body of code we think may be using a pattern, we should consider writing down some of the aspects of the code that we believe fall under a particular existing pattern or set of patterns.
In many cases of pattern analysis, we can find that we’re just looking at code that follows good principles and design practices that could happen to overlap with the rules for a pattern by accident. Remember: solutions in which neither interactions nor defined rules appear are not patterns.
If you are interested in venturing down the path of writing ...