0

Sometimes people use the phrase "Polymorphic method/function".

Does it mean:

  1. A method that takes a Polymorphic type as a parameter, and performs some operation on it. By "Polymorphic type" I mean a super-type with multiple sub-types.
  2. An abstract or virtual method in a super-type, with multiple sub-types that implement/override the method differently.
4
  • I'd say probably 2), but without context it's impossible to say. Who uses the phrase? Commented Aug 16, 2014 at 7:21
  • @KilianFoth Not sure, I've seen it used a couple of times.
    – Aviv Cohn
    Commented Aug 16, 2014 at 7:36
  • It can actually be both things depending on the language, feature and technology used. Runtime polymorphism is based on virtual methods, static polymorphism (like CRTP) is based on template parameters and template functions (something yo ueven don't mention). Some languages distinguish classes and interface, some other don't (and admit abstract mthods to be intermixed with implemented ones) ... Commented Aug 16, 2014 at 7:47
  • You can also have the case of a method that does the same thing on different types (parametric polymorphism). E.g. in Java a method add on a list will append an object to the list. The type parameter of the list (List<String>, List<Customer>) ensures that an object of the correct class is appended.
    – Giorgio
    Commented Aug 16, 2014 at 8:50

1 Answer 1

2

The therm "polymorphic", alone, means nothing more that "a noun or verb that can act differently depending on context".

You say "do" and something gets done. What is actually done ... depend on the something.

How this translated into programming depends on the chosen language, its features and the way you use those features to manipulate things.

Even C (that's not normally thought as an OOP language) can use a statement like a.(*do)() to do different things depending on a...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.