Book Review: PHP 5 Objects, Patterns and Practice(Page 2 out of 2)
The third part of the book is all about one thing: Design Patterns. In the first chapter of this part (chapter seven) you are introduced to the concept of design patterns, what they are and why you should use them. The author also introduces the "Gang of Four" and the famous "Patterns of Enterprise Application Architecture" by Martin Fowler. Although this chapter doesn't introduce any patterns yet, it's still a very interesting and useful chapter. If you're going to use design patterns, it's important to know about the background of them, and it's all explained in this chapter. I never knew anything about them myself, so I learnt a great deal from this chapter.
Chapter eight will take you through some important pattern principles. This chapter starts of with something called "The Pattern Revelation" in which the author mentions an anecdote in which he had a revelation once he discovered design patterns. To quote from the book:
"It wasn't until I discovered Design Patterns, otherwise known as the Gang of Four book, that I realized I had missed an entire design dimension."
After reading this book, you will probably feel the same way. I certainly do!
The rest of chapter eight talks about a few key principles of design patterns, and things you should look out for, like overusing design patterns.
In chapter nine you will be introduced to the first design patterns and the author explains the following patterns: the Singleton, the Factory Method and the Abstract Factory, which are grouped under "Generating Objects". Design patterns can be hard to understand, but the author does a good job at breaking them down. Each pattern is discussed in the same format: the problem, an example implementation, and the consequences of using this pattern. This gives you a good overview of each pattern, and I'm very pleased the author did it like this.
In chapters ten and eleven you will be introduced to more patterns, including the Composite pattern, the Observer pattern, the Visitor pattern, and more. In chapter ten I had my first eye-opener event, when I read about the Decorator pattern. I immediately recognized the problem I was having in one of my own scripts, and why the decorator pattern is the right way to fix it. Without this book I would've never considered the Decorator pattern, and probably would've used a really clumsy solution.
Chapter twelve is a really interesting one, and covers a topic I often don't see. It explains how to actually present data to a visitor, using various design patterns, such as the Front Controller or a Page Controller. The author demonstrates a complete implementation of a simple script which can be used to manage theater events. I found this chapter really useful, and I bet many others do too, because it shows a good OOP implementation of handling different pages.
Chapter thirteen is the first chapter of the third part, and leaves all the design patterns and OOP, and takes a look at a complete different aspect of programming: how to do it as effective as possible. This is something you don't see covered often in a PHP book, as it's usually about the PHP itself, but in this book you will learn about other topics such as PEAR, version control (using CVS), unit testing, generating documentation with phpDocumentor and creating automated builds with the Phing project. In part three all these topics are covered in depth.
Finally, part four, which consists of only chapter eighteen, simple rehashes everything that has been said in the book, and takes a quick glance at the most important things. This is not really an important chapter, since it's all stuff that has been covered already, but it's still nice to get everything in a clear overview.
If you're just starting with PHP, you shouldn't buy this book, and instead start with a simpler one.
But if you've already been using PHP for a while, I can highly recommend this book to bring you to the next dimension of programming. It will introduce all the necessary concepts, and explain everything with simple (as possible) examples. I've been struggling with OOP and design patterns myself for the past few months, and I've finally begun understanding it after reading this book. It's definitely been a revelation for me!
So, if you want to know more about OOP, design patterns or design, this book is an excellent starting point!