Monday, October 29

Polymorphism Concept in OOP

  • Polymorphism is declaring a uniform interface that isn't type aware, leaving implementation details to concrete types that implement the interface.
  • ad-hoc polymorphism (looks like a duck and walks like a duck => is a duck). Can be seen in Haskell and Python for example.
  • generic polymorphism (where a type is an instance of some generic type). Can be seen in C++ for example (vector of int and vector of string both have a member function size).
  • subtype polymorphism (where a type inherits from another type). Can be seen in most OO programming languages (i.e. Triangle is a Shape).
  • Wikipedia: Polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. Pretty straightforward for me.
  • Multiple implementations of the same interface.
  • Multiple forms of a single object is called Polymorphism.
  • Different objects can respond to the same message in different ways, enable objects to interact with one another without knowing their exact type.
  • Polymorphism is a programming feature that allows an object to have many types ('shapes') and lets you treat it as any of those types depending on what you need to do without knowing or caring about its other types.
  • Polymorphism at the lower level is the ability to invoke methods that are defined by the implementors of an interface from the interface instance.
  • Polymorphism is ability of an object to appear and behave differently for the same invocation. ex: each animal appear and sound differently ( when you hit it.

No comments:

Post a Comment