網路城邦
上一篇 回創作列表 下一篇  字體:
Design Guidelines for Is-A Hierarchies, by John A. Grosberg, DDJ June 1997
2010/03/07 12:57:10瀏覽745|回應0|推薦0
< Design Guidelines for Is-A Hierarchies >
by John A. Grosberg, Dr. Dobbi's Journal  June 1997

很棒的一篇技術文章!

作者先以一個簡單的 Rectangle - Square 範例,舉出許多教科書或業界在設計實做 Is-A Hierarchy 時所常犯的不當之處,並歸納出兩個準則來做為分析設計的參考依據:
  1. Including Region ---> an abstract class and a concrete class (difference class)
  2. Non-Including Region ---> concrete class
隨後的進一步探討範例 ── (Aminal, Dog, Cat)、(Animal, Mammal, Dog) 以及 (Animal, Mammal, Egg Laying),則闡述了作者獨到的見解與令人深思的啟發,也把 Polymorphism 與 Multiple Inheritance 的部分精髓以實例做了精闢的解析。

John A. Grosberg 認為,一個設計良好的 Is-A Hierarchy 應當只有使用到兩種類別的 class ── Abstract Class 與 Concrete Class;如果軟體的實做設計中使用了 mixed class ── one that has both instances and subclasses,則不是一個設計良好的 Is-A Hierarchy;John 將此見解稱之為 True Is-A Hierarchy。

若以 John 的 True Is-A Hierarchy 來做為判斷的準則,則許多的軟體開發案與教科書的範例程式,其設計觀點與程式實作都違反了 True Is-A Hierarchy。

在文章結束之前,John 對如何將
不是 True Is-A Hierarchy」的 legacy code 或 library 改寫成 True Is-A Hierarchy,提出了 Private Inheritance 或 Delegation 的解決之道,並以最原始的 Rectangle - Square 範例來做實地的解說。

雖然是一篇歷時十幾年的文章,但卻是一篇剖析精闢、範例舉得言簡意賅的好文章。






( 創作其他 )
推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=chungchia&aid=3832034