home 首页 » 精彩博客 » 博客查看

Book Review: Object-Orientated Programming with PHP5 (Hasin Hayder, Packt Publishing) - David Goodwin

 2008-02-27 18:40:17 

原文地址:http://codepoets.co.uk/book-review-object-orientated-programming-php5-hasin-hayder-packt-publishing

mayongzhan 译

After an email out of the blue from someone at Packt publishing, here's a review of "Object-Orientated Programming with PHP5"

I don't think I've done a book review before, so apologies in advance if it's not structured in any logical manner.

Contents

Briefly summarised, the book's chapters are :

  1. OOP vs Procedural Programming (what is OOP?, why?, differences between etc)
  2. Kick Starting OOP (objects, inheritance, polymorphism etc)
  3. More OOP (useful PHP functions, exceptions, iterators etc)
  4. Design Patterns (Strategy, Singleton, Adapter, Observer, Decorator etc)
  5. Reflection and Unit Testing (phpUnit)
  6. Standard PHP Library
  7. Databases in an OOP way (MySQLi, PDO, Abstraction layers - PEAR::MDB2, ADODB and Active Record)
  8. Cooking XML with OOP (SimpleXML, xpath, Dom)
  9. MVC / Frameworks

It's aimed at beginner/intermediate programmers

Pros

  • Introduces SPL (Standard PHP Library) in reasonable depth
  • Introduces PDO, PEAR::MDB2, AdoDB and MySQLi
  • Introduces the main OO patterns
  • Introduces MVC and frameworks

Cons

  • It's only 250 pages
  • It doesn't go into much depth in any particular area
  • I seemed to notice plenty of grammatical errors in the book - often missing pluralisations. I'm no grammatician, and some would argue in no position to lecture... but even so, somehow I expect published books to be near perfect.
  • There were occasional spelling mistakes in the code (e.g. s/Mehod()/Method())
  • Some of the example code was poorly presented/written (see below for example)
  • 10 pages are spent providing the PHPUnit API, and the last chapter focuses on what I assume is the author's home made framework. I feel the pages would have been better spent covering one of the main frameworks (e.g. Zend or CodeIgnitor). Having said that, I found it vaguely interesting to see how someone else had tackled the problem - but I doubt the book's target market of beginners/intermediate programmers will.

Random Code Example

To give a better flavour of the book, chapter 4 covers various software patterns. One of which is the decorator pattern. Part of the example shown is as follows :

 

$post = new Post();
$comment = new Comment();
$post->filter();
$comment->filter();
if($BBCodeEnabled==false && $EmoticonEnabled==false) {
$PostContent = $post->getContent();
$CommentContent = $comment->getContent();
}
elseif($BBCodeEnabled==true && $EmoticonEnabled==false) {
$bb = new BBCodeParser($post);
$PostContent = $bb->getContent();
$bb = new BBCodeParser($comment);
$CommentContent = $bb->getContent();
}
elseif($BBCodeEnabled==false && $EmoticonEnabled==true){
$em = new EmoticonParser($post);
// etc.
}

 

I feel this would have been better written as :

 

$post = new Post();
$post->filter();
$comment = new Comment();
$comment->filter();

if($BBCodeEnabled==true) {
$post = new BBCodeParser($post);
$comment = new BBCodeParser($comment);
}
if($EmoticonEnabled==true){
$post = new EmoticonParser($post);
$comment = new EmoticonParser($comment);
}
$PostContent = $post->getContent();
$CommentContent = $comment->getContent();

 

But I digress....

Summary

As you might see, I have slightly mixed feelings about the book. I think it grew on me as I read more of it, and some of my initial negativity wore off over time.

The book does provide a good grounding in OOP and Software Design Patterns. However, it doesn't really go into enough detail when it covers PDO, MySQLi or PEAR::MDB2 for it to be a usable self contained resource.

I think it would have been better for the book to drop the section on the home grown MVC framework, and the PHPUnit API and expand some of the examples. It doesn't cover what it does in enough depth on it's own - so don't buy it if you're looking to gain a working knowledge of something it covers (e.g. PDO, AdoDB or the like) from scratch.

The book does maintain something like a 50:50 ratio between code and text. At times this does make it feel a little like the author is padding the book with code, and duplicating the API at php.net for no real reason.

Disclaimer - I got the book for free, as long as I published a review.....

收藏:

评论:共 
34
 条