需要用 OOAD 来解释一下“is a”等级制度
我购买了面向对象的分析和设计与应用程序,第 64 页段落2 有关于“是一个”层次结构的解释,如下所示。
就其“is a”层次结构而言,高级抽象是泛化的,低级抽象是专门化的。因此,我们说 Flower 类比 Plant 类具有更高的抽象级别。
据我了解,我认为植物比花更普遍,然后花类处于比植物较低的抽象级别。
我想知道此时我的理解是正确的还是书上的正确?请澄清我。
I have purchase Object-Oriented Analysis and Design with Applications, at page 64 paragraph 2 has explain about "is a" hierarchy like below.
In terms of its “is a” hierarchy, a high-level abstraction is generalized, and a low-level abstraction is specialized. Therefore, we say that a Flower class is at a higher level of abstraction than a Plant class.
As I understand, I think plant is more generalize that flower then flower class is at lower level of abstraction than plant.
I want to know at this point my understanding is correct or the book is correct? Please clarify me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我同意,这句话是错误的。根据这里的定义,Plant 比 Flower 处于更高的抽象级别:定义是正确的,示例中的名称已互换。
I agree, this quote is wrong. By the definition here, Plant is at a higher level of abstraction than Flower: the definition is correct, the names in the example are transposed.
层次结构的植物和花卉示例可能是我听过的最糟糕的示例!
汽车是——车辆。狗是哺乳动物。储蓄账户是一个(n)账户。这些都是典型且容易理解的例子。
The plant and flower example for is-a hierarchies is probably the worst I've ever heard!
A car is-a vehicle. A dog is-a mammal. A savings account is-a(n) account. All these are typical and easily understood examples.
你引用的内容听起来不太正确。假设 Flower 继承自 Plant,我会理解 Plant 比 Flower 处于更高的抽象级别。因此,
花
是
植物但是
植物不一定是花
What you have quoted doesn't sound quite right. I would have understood Plant to be at a higher level of abstraction than Flower, assuming Flower inherits from Plant. Therefore,
A Flower
is a
Plantbut
A Plant is not necessarily a Flower
我不会说“花是植物”这句话是正确的,在我看来,植物有花。我认为缺少一些上下文。
我认为这本书的作者在这里解释了继承层次结构。如果一个实体位于层次结构的顶部,则它或需要比层次结构中位于其下方的实体更加概括(或抽象)。让一个实体继承另一个实体但比其父实体更抽象(转换为从具体类继承的抽象类)是糟糕的设计。
I wouldn't say the statement "A Flower is a Plant" is true, in my opinion a Plant has-a Flower. I think there is some context missing.
I think the author of the book is explaining about inheritance hierarchies here. If an entity is at the top of the hierarchy, it is or needs to be more generalized (or abstract) than the ones below it in the hierarchy. It is bad design to have an entity inheriting from another entity but be more abstract than its parent (translating to an abstract class inheriting from a concrete class).