My Question:
What are some good examples of design patterns used in CakePHP?
Why Use CakePHP As My Context
I’ve been using CakePHP for about a year so I think it’s easier for me to think in that context. CakePHP is also rich in design pattern use (I’m confident of that)–I just don’t know what patterns are being used other than a few obvious ones.
Example Books I’ve been Reading On the Subject:
I’m reading the following books which all cover design patterns to one extent or another; unfortunately they mostly use Java and C++ code examples which makes it harder for me to get a grip on the design patterns on a practical level (I’m a PHP developer so its hard for me to absorb it):
“Patterns of Enterprise Application Architecture”, by Martin Fowler
“Head First Design Patterns”, by Gang of Four (Eric Freeman, Elisabeth Freeman, Kathy Sierra & Bert Bates) (2004)
“Design Patterns: Elements of Resuable Object Oriented Software)”, by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides)
Examples of Patterns I Can Observe in CakePHP
-I’m guessing the config file uses something akin to the factory pattern
-maybe $this->params is using something related to the observer pattern? I’m not sure on that…
-MVC (obvious! since Cake PHP uses the MVC file structure)
-ORM (another very obvious one)
-Maybe the HTML helper is using the decorator pattern?
Summary
I don’t expect anyone to go down the line and identify all the patterns used in CakePHP–I’m just looking for a few examples of design patterns that should be obvious that I’m missing.
One that comes to mind is the concept of mixins. Not exactly a pattern but actually a language feature available in some languages (ie. modules in Ruby) but not in others (ie. Java). It will be coming to PHP when 5.4 goes stable and we get traits, but CakePHP’s model behaviours are a good example of mimicking this kind of multiple inheritance where it normally isn’t possible.