There are many patterns to keep track of. To help sort this out, the Gang of Four has grouped patterns into three general categories, as shown in Table 17-1.[1]
[1] Gamma, E., Helm, R., Johnson, R., Vlissides, J., Design Patterns: Elements of Reusable Object-Oriented Software, Reading, Mass.: Addison-Wesley, 1995, p. 10.
Category | Purpose | Examples in This Book | Use For |
---|---|---|---|
Structural | Bring together existing objects | Handling interfaces | |
| Relating implementations to abstractions | ||
Behavioral | Give a way to manifest flexible (varying) behavior |
| Containing variation |
Creational | Create or instantiate objects |
| Instantiating objects |
When I first started studying design patterns, I was surprised to see the Bridge and Decorator patterns were structural patterns rather than behavioral patterns. After all, they seemed to be used to implement different behaviors. At the time, I simply did not understand the GoF's classification system. Structural patterns are for tying together existing function. In the Bridge pattern, we typically start with abstractions and implementations and then bind them together with the bridge. In the Decorator pattern, we have an original functional class, and want to decorate it with additional functions.
I have found it valuable to think of a fourth category of patterns, one whose primary purpose is to decouple objects from each other. One motivation for these is to allow for scalability or increased flexibility. I call this category of patterns decoupling patterns. Since most of the patterns in the decoupling category belong to the Gang of Four's behavioral category, I could almost call them a subset of the behavioral category. I chose to make a fourth category simply because my intent in this book is to reflect how I look at patterns, focusing on their motivations—in this case, decoupling.
I would not get too hung up on the whys and wherefores of the classifications. They are meant to give insights into what the patterns are doing.
This chapter discusses the Observer pattern, which is the best example of a decoupling pattern pattern there is. The Gang of Four classifies Observer as a Behavioral pattern.