class 的物理表示是什么?
What is a physical representation of a class?
在“设计模式 - 可重用面向对象软件的元素”第 1 章第 1.6 节“继承与组合”部分的“使重用机制发挥作用”下,作者在谈论继承的缺点:
Second, and generally worse, parent classes often define at least part of their subclasses' physical representation.
(我强调的)
在此上下文中,物理表示是什么意思?我正在做一些搜索,发现 this Whosebug question 在答案中物理被定义为 为对象分配内存 .
这是否意味着在使用继承时,继承对象的内存分配部分由对象的父对象定义?
如果是,那换句话说是什么意思?为什么这是一个缺点?
它在谈论两件事:
- 主要是父class方法的实现(例如,父class的代码)
- 还有父类定义的实例字段的内存布局class
句子后面是:
Because inheritance exposes a subclass to the details of its parent's implementation, it's often said that "inheritance breaks encapsulation" [Sny86]. The implementation of a subclass becomes so bound up with the implementation of its parent class that any change in the parent's implementation will force the subclass to change.
直接引用父class方法的实现。
在“设计模式 - 可重用面向对象软件的元素”第 1 章第 1.6 节“继承与组合”部分的“使重用机制发挥作用”下,作者在谈论继承的缺点:
Second, and generally worse, parent classes often define at least part of their subclasses' physical representation.
(我强调的)
在此上下文中,物理表示是什么意思?我正在做一些搜索,发现 this Whosebug question 在答案中物理被定义为 为对象分配内存 .
这是否意味着在使用继承时,继承对象的内存分配部分由对象的父对象定义? 如果是,那换句话说是什么意思?为什么这是一个缺点?
它在谈论两件事:
- 主要是父class方法的实现(例如,父class的代码)
- 还有父类定义的实例字段的内存布局class
句子后面是:
Because inheritance exposes a subclass to the details of its parent's implementation, it's often said that "inheritance breaks encapsulation" [Sny86]. The implementation of a subclass becomes so bound up with the implementation of its parent class that any change in the parent's implementation will force the subclass to change.
直接引用父class方法的实现。