类与对象层次结构
你如何解释类层次结构。
我认为我的谷歌力量已经下降,因为当我搜索“类层次结构”这个术语时,我得到了一些关于类如何组织以及它们之间的继承关系的示例。这就是类层次结构的全部内容吗?如何向 C 开发人员解释类层次结构?
另外,类层次结构和对象层次结构之间有什么区别?
事实上,我周六要向我的办公室同事做一次演讲,并遇到了很多理论主题:(
任何帮助将不胜感激。
非常感谢
How do you explain class hierarchies.
I think my google power has gone down because when i searched for 'Class hierarchies' as the term i got a few examples of how classes are organized and the inheritance relationship between them. Is that all about class hierarchies? How do you explan class hierarchy to a C developer?
Also whats the difference between class hierarchy and object hierarchy?
Actually i am due a presentation on Saturday to my office mates and coming across so many theoretical topics :(
Any help would be appreciated.
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试用几行来回答。
类层次结构可能是指由类及其之间的继承链接组成的结构。例如,您可能有从
类Vehicle
继承的类Car
,等等。这就构成了一个类层次结构。现在,当您使用
new
运算符创建Car
实例时,您将获得一个Car
对象;不涉及等级制度。也就是说,不存在像两个类那样的“两个对象通过继承链接在一起”。我们可以说,在实例化时,类层次结构“变得扁平化”。因此,短语对象层次结构通常指的是整体/部分结构。您可能有另一个类,可能名为
Wheel
,加上从Car
到Wheel
的引用,以便汽车最多可以包含四个轮子(想象一下汽车对象中的轮子阵列,或者任何其他类型的容器(如果您愿意)。这种安排构成了运行时对象的图形(而不是层次结构),其中整体/部分(有时称为“聚合”或“组合”)关系是主要链接。总之:类层次结构和对象层次结构完全不同且不相关。
我希望这有帮助。
I'll try to answer in a few lines.
A class hierarchy probably refers to the structure composed by classes and inheritance links between them. For example, you may have
class Car
that inherits fromclass Vehicle
, and so on. That makes up a class hierarchy.Now, when you create an instance of
Car
using thenew
operator, you obtain aCar
object; there is no hierarchy involved. That is, there is no "two objects linked together through inhertance" like the two classes are. We can say that, at instantiation time, class hierarchies "get flattened".The phrase object hierarchies, therefore, often refers to whole/part structures. You may have another class, perhaps named
Wheel
, plus a reference fromCar
toWheel
so that cars may contain up to four wheels (imagine an array of wheels in a car object, or any other kind of container if you wish). This arrangement makes up a graph (rather than a hierarchy) of objects ar run time where whole/part (sometimes called "aggregation" or "composition") relationships are the major links.In summary: class hierarchies and object hierarchies are totally different and not related.
I hope this helps.