多态和泛化有什么区别。我看到它们在 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()
并且你有该类的不同特化(与泛化相反)(例如,具体类Cat
和 Dog
) 然后你可以通过调用 sound()
来处理多态 Animal
。如果您有一只猫
,它会喵喵叫,如果您有一只狗
,它会吠叫。
关于oop - UML 中的多态性和泛化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51424798/