类与对象层次结构

发布于 2024-10-11 16:03:03 字数 230 浏览 2 评论 0原文

你如何解释类​​层次结构。

我认为我的谷歌力量已经下降,因为当我搜索“类层次结构”这个术语时,我得到了一些关于类如何组织以及它们之间的继承关系的示例。这就是类层次结构的全部内容吗?如何向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-10-18 16:03:03

我会尝试用几行来回答。

类层次结构可能是指由类及其之间的继承链接组成的结构。例如,您可能有从类Vehicle继承的类Car,等等。这就构成了一个类层次结构。

现在,当您使用 new 运算符创建 Car 实例时,您将获得一个 Car 对象;不涉及等级制度。也就是说,不存在像两个类那样的“两个对象通过继承链接在一起”。我们可以说,在实例化时,类层次结构“变得扁平化”。

因此,短语对象层次结构通常指的是整体/部分结构。您可能有另一个类,可能名为 Wheel,加上从 CarWheel 的引用,以便汽车最多可以包含四个轮子(想象一下汽车对象中的轮子阵列,或者任何其他类型的容器(如果您愿意)。这种安排构成了运行时对象的图形(而不是层次结构),其中整体/部分(有时称为“聚合”或“组合”)关系是主要链接。

总之:类层次结构和对象层次结构完全不同且不相关。

我希望这有帮助。

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 from class Vehicle, and so on. That makes up a class hierarchy.

Now, when you create an instance of Car using the new operator, you obtain a Car 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 from Car to Wheel 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文