Author: Matt Zandstra
Publisher: Apress, 2010
Aimed at: PHP Programmers
Pros: A good introduction to objects
Cons: PHP isn't the best language for this.
Reviewed by: Mike James
An object-oriented book for a scripting language? Can this work?
This an excellent book and, if you have always wanted to find out about object-oriented programming but you mainly program in PHP, just buy a copy.
However, I do have some reservations and the first is that I wish the book wasn't focused on PHP. This is not because PHP isn't a reasonable language in which to write practical things, but it isn't a language that makes it easy to explain classical object-oriented ideas. This said, the book does a great job and even manages to use PHP's oddities to better illustrate how object- oriented ideas work.
The book starts out with a look at the fundamentals of object-oriented programming in PHP. If you learned PHP as a scripting language then this will bring you up-to-date. Part 1 of the book is a single chapter that muses on objects, patterns and so on and places PHP in context.
Part 2 is mostly about learning PHP's object-oriented features. Your basic OOP course in PHP consists of chapters 2, 3 and 4. Chapter 5 look at some more advanced topics - packages and reflection. Chapter 6 is an introduction to a broader general philosophy of objects - cohesion, coupling, orthogonality, polymorphism and so on. It is a lead-in chapter to the next major part of the book on patterns.
Part 3 works its way through classical object-oriented patterns, i.e. the "gang of four" catalog. Chapter 7 gives an overview of what patterns are all about. If you have worried in the past about the vague and waffly nature of the whole idea of a pattern then don't, because this is all about practical ways of using objects. The only problem is that it is something of a jump in sophistication from parts 1 and 2.
The author is not concerned with the line-by-line details of how to code in PHP, but the overall architecture of the application. By necessity this means that the examples have to be bigger and hence they can be more difficult to follow. More importantly, it is possible to follow them and still not see what the objection is that the author has to the proposed solution and why the pattern being explained solved the problem. This is another level of thought. Chapter 9 deals with object generation patterns, Chapter 10 deals with flexible objects, Chapter 11 is about tasks, Chapter 12 is on enterprise patterns and Chapter 13 deals with database patterns. It is a long haul and you need to work at it to follow the ideas. If you have already met the patterns elsewhere then you probably won't get much more from this explanation as the way that they are expressed in PHP is fairly obvious.
Part 4 is an altogether different experience. Instead of being about high-minded architectural problems, it digs into the practicalities of using PHP in the real world. Chapter 14 is called Good and Bad Practice and it works through all of the basic ideas such as "don't reinvent the wheel".
Then we have a chapter on PEAR and packages, documentation with phpDocumentor, version control with Subversion, testing and PHPUnit, automated builds and continuous integration. All very useful but not to every PHP programmer. Which parts you need to read depends very much on the sort of PHP application you are working on. This said, there is something for everyone and you need to know that all of these ideas at least exist.
Part 5 is a single-chapter conclusion that sums up the object-oriented idea. If you have read the book, it will all make good sense, perhaps to the point where it is all too obvious.
This is a good book on object philosophy and practice. The explanations are always clear, but sometimes they are involved and need you to think about the ideas. If you have looked at books on object-oriented design and patterns in particular and been put off by the excessive academic tone, or the use of waffle to cover up the key ideas, rest assured - this is not that sort of book. In most cases the explanations attempt to point out what is wrong with an initial solution and how the pattern helps to make the code better. I found the layout and presentation of the book messy and this made it harder to read but the effort is worth it.
Recommended if your first language is PHP and you want to find out how objects, patterns and other modern programming ideas could help you build better applications. However, it isn't for the beginner.