網址改寫(其二)

2006 年 十一月 9 日 (星期四) 2:18 pm
分類:電腦

繼上回發表了〈網址改寫〉,初步驗證想法可行之後,接下來就是逐一實現該文文末所列的待辦事項。不過,在新增功能之前,程式架構還是得先 refactor 過,才能從容因應未來的成長,也比較能夠見人(萬一有一天我想 open source 的話……)。

儘管 “Top 21 PHP Programming Mistakes” 一文將 OO 列為 PHP 的第 11 罪狀:

The OO paradigm is a wonderful concept. It has numerous benefits, the most notable being the ability to reuse code easily. However, as we’ve all come to understand: ‘PHP is not an OO language’.

While PHP does offer adequate object oriented support, it is neither efficient nor wise to use its object oriented features when you can make use of other methods to achieve the same result. The reason for this is that PHP’s OO support is not full blown.

但我還是認為 OO 風格比較容易使用、擴充及維護,尤其是搭配 factory 及 delegation 機制,架構漂亮多了。反正經過初步實驗,效能並沒有降低多少,所以我還是 refactor 成 OO 風格。

除了 refactoring 之外,本次改版也是為了處理 Amazon 的網址。由於我常在 blog 裡徵引書籍資訊,因而經常需要手動調整 Amazon 多變的網址形式;若將瀏覽器的 cookie 關掉,Amazon 還會啟動 URL rewriting 機制置入 session id,讓網址更複雜。它的網址形式有多麼特別嗎?請看:

  1. http://www.amazon.com/gp/product/0394404289/
  2. http://www.amazon.com/exec/obidos/ASIN/0394404289/
  3. http://www.amazon.com/Prophet-Kahlil-Gibran/
    dp/0394404289/
  4. http://www.amazon.com/Prophet-Kahlil-Gibran/
    dp/0394404289/ref=pd_sim_b_1/002-0513074-2272042

我很佩服他們能將簡單的 ASIN 檢索變出這麼多花樣。

程式寫完了。從今以後,我就不再需要手動處理這麼一大堆變形了,寫起 blog 應該會更輕鬆愉快吧。 :)

相關閱讀


◤您也可以閱讀以下文章:


留言回應

[檢核碼]  


Allowed XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

本站已啟用 spam 防護機制。為避免系統誤判,請在按下按鈕之前,先備份您的留言,以防不測。如果您一直無法順利留言,請改用 email 方式。
此外,如果您想留的言與本篇文章及討論串無關,也請轉而點選這裡。謝謝您!