書評Object-Orientated Programming with PHP5 – 馬永占 譯

來源:互聯網
上載者:User

著作權聲明:原創作品,允許轉載,轉載時請務必以超連結形式標明文章原始出版、作者資訊和本聲明。否則將追究法律責任。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.....
 
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.