oop - UML 中的多态性和泛化

标签 oop object polymorphism uml generalization

多态和泛化有什么区别。我看到它们在 UML 中看起来很相似。它们相同吗?

最佳答案

让我们看看牛津词典:

generalization | ˌjen(ə)rələˈzāSH(ə)n |

noun

a general statement or concept obtained by inference from specific cases: he was making sweeping generalizations.

• the action of generalizing: such anecdotes cannot be a basis for generalization.

UML 有一个图形表示,它是一 strip 有开放三角形的单线,指向一般类。

polymorphism | ˌpälēˈmôrfizəm |

noun

the condition of occurring in several different forms: the complexity and polymorphism of human cognition.

[...]

Computing a feature of a programming language that allows routines to use variables of different types at different times.

这是泛化的某种用途。例如,如果你有一个抽象类 Animal,它有一个操作 sound() 并且你有该类的不同特化(与泛化相反)(例如,具体类CatDog) 然后你可以通过调用 sound() 来处理多态 Animal。如果您有一只,它会喵喵叫,如果您有一只,它会吠叫。

关于oop - UML 中的多态性和泛化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51424798/

相关文章:

Scala 类的多重继承

c# - 扩展(而不是更改)新行为的搜索类?

javascript - jQuery/JS : Sorting array based upon another array?

c# - 为什么 json 序列化器不符合多态性?

delphi - 面向对象和序列化

asp.net-mvc - 如何构建通用存储库

javascript - jQuery 数组参数和each()

Java传递数组和对象值

c++ - 使用多态子类各自的方法

c++ - 设置多态成员变量的特定参数的通用方法