The phpPatterns.com website has a new pattern posted this morning - the Decorator Pattern
According to their site: The decorator pattern provides us with a mechanism for adding functionality to objects at runtime, as an alternative mechanism to creating additional child classes.
Basically, this pattern can help you do things to objects that have already been created, rather than scraping the whole thing and getting a new one. The example they give is a pretty clear "file listing" display class, that allows you to sort on name, type and file's size. The Decorator class just extends the FileList class, and overwrites some of the methods in the FileList to create the sort. Of course, as an example near the end of the article, they show you an alternative that doesn't overwrite the parent's methods to get the job done, and, instead, just adds another "layer" between it and the main FileList class.




