虽然subtype和subclass是OOP中最基本的问题之一,但我是在读《冒号课堂》的时候才开始注意到这个问题。我想国内的程序员不能区分subtype和subclass的不在少数。下面这个资料对于subtype和subclass讨论得比较深入,贴上来分享:
http://www.cs.princeton.edu/courses/archive/fall98/cs441/mainus/mainus.html
虽然subtype和subclass是OOP中最基本的问题之一,但我是在读《冒号课堂》的时候才开始注意到这个问题。我想国内的程序员不能区分subtype和subclass的不在少数。下面这个资料对于subtype和subclass讨论得比较深入,贴上来分享:
http://www.cs.princeton.edu/courses/archive/fall98/cs441/mainus/mainus.html
非常好的文章,多谢分享。其中谈到subclass与subtype的区别时是这样说的:Subclasses allow one to reuse the code inside classes - both instance variable declarations and method definitions. Thus they are useful in supporting code reuse inside a class. Subtyping on the other hand is useful in supporting reuse externally, giving rise to a form of polymorphism。即:子类用于类的内部重用,子类型用于外部重用。这个与《冒号课堂》中提到的观点本质上是一致的:实现继承消费可重用的旧代码,接口继承生产可重用的新代码;接口继承不是为了代码重用,而是为了代码被重用。
另:该文章的PDF版可到 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.9.7539&rep=rep1&type=pdf 下载。
是的,和《冒号课堂》的观点基本一致。区分了subtype和subclass就能把继承和多态的关系理清楚了。同时,对于以前不太容易区分的interface与abstract class的选择问题也会更清楚。使用interface是为了subtype,使用abstract class则包含了subtype和subclass。记得书中比喻abstract class是半成品。
CiteSeer是个好地方!
是的,CiteSeerx有大量高质量的学术文章。
You must log in to post.