Polymorphism

  • Ad Hoc / Overloading: functions/operators with same names but different implementations. e.g.
    • The operator+(), usually one for ints, one for floats, etc.
    • Some languages allow you to override existing operators, e.g. C++, Python, Haskell

Polymorphism

  • Inclusive / Subtype / Subclass: when a data type can refer to a set of types. e.g.
    • An array of a Parent type (references) is ok holding different Child types
    • Passing a Child type object as a parameter to a function argument that is a reference of a Parent type

Polymorphism

  • Parametric: a function that lets its parameters vary by type or number. i.e. reusing the same implementation for different types. e.g.
    • Optional parameters: print in Python and printf in C
    • Generic parameters: sizeof in C, template in C++, Generic in Java