Ever since MVC started making inroads in the PHP community, the acronym’s “V” has been unfairly reduced to the level of a plain template whose responsibility was limited to rendering a few HTML pages, but views not only can be full-fledged objects carrying state, but also observers of a model, flexible enough to accommodate and react accordingly to fluctuations whenever the model’s state changes. In this two-part tutorial you’ll see how you can implement from scratch a couple of customizable view handling modules by sinking our teeth into the goodies of the Composite and Decorator patterns. In this part we’ll focus on the Composite pattern.
The Composite and Decorator patterns are among the most overlooked paradigms in PHP, but can provide for more flexible view objects. this is the second in a two-part series discussing the patterns, this time focusing on the Decorator pattern.