oopobjectpolymorphismumlgeneralization

Polymorphism and Genaralization in UML


What is the difference between polymorphism and Generalization . I saw that they look similar in UML. Are they same ?


Solution

  • Let's look into the Oxford dictionary:

    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 has a graphical representation for that which is a solod line with an open triangle towards the general class.

    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.

    That's a certain use of generalization. If you have, say, an abstract class Animal which has an operation sound() and you have different specializations (the opposite of generalization) of that class (e.g. a concrete class Cat and Dog) then you can treat the polymorph Animal by calling sound(). In case you have a Cat it would meow and for a Dog it would bark.