`
txf2004
  • 浏览: 6874342 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

书评Object-Orientated Programming with PHP5 - 马永占 译

阅读更多

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan

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

突然接到Packt publishing的邮件,内容是关于”Object-Orientated Programming with PHP5“的书评。
以前从来没有做过书评,对于评论的样式内容结构的不合理,在此对读者表示歉意。

内容
简要概述,这本书的章节是:
面向对象(OOP)与程序设计(PS:应该是面向过程吧)(什么是OOP?,为什么要OOP?, 两者的区别等等)
开始 OOP (对象(封装),继承,多态等等)
高级OOP (使用 PHP 函数,异常,迭代等等)
设计模式Design Patterns (Strategy, Singleton, Adapter, Observer, Decorator etc)(这里就不译了)
反射和单元测试(phpUnit)
Standard PHP Library (著名的SPL)
OOP数据库 (MySQLi, PDO, 数据持久层Abstraction layers - PEAR::MDB2, ADODB and Active Record)
OOP和XML (SimpleXML, xpath, Dom)
MVC / Frameworks
针对初/中水平开发人员


支持
适当的介绍了 SPL (Standard PHP Library)
介绍了 PDO, PEAR::MDB2, AdoDB and MySQLi
介绍了主要的面向对象设计模式
介绍了MVC和frameworks(框架)

反对
只有250页
不够深入
很多语法错误,希望在出版的时候能够改正这些错误。
有很多拼写错误 (e.g. s/Mehod()/Method())
有些例子很差(请见下文)
十页的篇幅去讲PHPUnit API,在最后讲使用框架开发一个项目,我觉得应该利用一部分篇幅将一个主要的框架,例如zend或者codeignitor。话虽如此,我觉得这本书还是不错的,尤其是能学到别人怎么解决问题,这对于初中级开发人员会有很大的帮助。


代码实例
为了使这本书更有意思,第四章讲了很多主要的设计模式。其中一个decorator模式,部分代码如下:

$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.
}我觉得这样写会更好:

$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....

概要
正如你所看到的,这本书是我看过的书中质量非常好的。(这段作者的感慨)
这本书围绕着面向对象OOP和设计模式Design Patterns,适当的涵盖PDO, MySQLi 或PEAR::MDB2等概念。
我认为应该减少一些章节(PDO,ADODB)来增加 MVC,框架framework, PHPUnit API 和一些例子。这些内容本身深度不够 - 所以如果你想从零开始使用PDO,ADODB或者想要得到些实际的经验,那么建议还是不要买此书,这会让你失望的。
这本书文字和代码的比例是50:50。这有点让人感觉到作者是在凑字,是在用API和php.net上的文档来填充这本书。
免责声明: - 略






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

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 :
OOP vs Procedural Programming (what is OOP?, why?, differences between etc)
Kick Starting OOP (objects, inheritance, polymorphism etc)
More OOP (useful PHP functions, exceptions, iterators etc)
Design Patterns (Strategy, Singleton, Adapter, Observer, Decorator etc)
Reflection and Unit Testing (phpUnit)
Standard PHP Library
Databases in an OOP way (MySQLi, PDO, Abstraction layers - PEAR::MDB2, ADODB and Active Record)
Cooking XML with OOP (SimpleXML, xpath, Dom)
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.....


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics