- 冒号空间 - https://blog.zhenghui.org -

Reply To: subtype和subclass

非常好的文章,多谢分享。其中谈到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 下载。


Share