Roly's Blog

Whatever will be, will be, the future's not ours to see.

0%

Polymorphism

Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which can contain data and code: data in the form of fields (often known as attributes or properties), and code in the form of procedures (often known as methods).

OOP has four main features:

Encapsulation

Wrapping data and code together into a single unit, like a gift.

Abstraction

Hiding unnecessary details and showing only the important ones, like a summary of a book.

Inheritance

Creating new objects based on existing objects, like a child inheriting traits from their parents.

Polymorphism

Allowing objects to behave differently depending on their type, like a car and a boat both being able to “move” but in different ways.

Polymorphism forms

In object-oriented programming, polymorphism is the provision of a single interface to entities of different types. The concept is borrowed from a principle in biology where an organism or species can have many different forms or stages.

The most commonly recognized major forms of polymorphism are:

  • Ad hoc polymorphism: defines a common interface for an arbitrary set of individually specified types.
  • Parametric polymorphism: not specifying concrete types and instead use abstract symbols that can substitute for any type.
  • Subtyping (also called subtype polymorphism or inclusion polymorphism): when a name denotes instances of many different classes related by some common superclass.

Ad hoc polymorphism

It is a kind of polymorphism in which polymorphic functions can be applied to arguments of different types, because a polymorphic function can denote a number of distinct and potentially heterogeneous implementations depending on the type of argument(s) to which it is applied.

Function overloading

Operator overloading

Parametric polymorphism

Generic function
Generic programming

Subtyping

Virtual function
Single and dynamic dispatch

Reference

https://en.wikipedia.org/wiki/Object-oriented_programming

https://en.wikipedia.org/wiki/Polymorphism_(computer_science)

https://www.naukri.com/code360/library/characteristics-of-object-oriented-programming

https://www.geeksforgeeks.org/introduction-of-object-oriented-programming/