Product Design, Manufacturing & Innovation Resources
Home » Polymorphism (programming)

Polymorphism (programming)

1967
  • Christopher Strachey
Computer programming workspace demonstrating polymorphism with code snippets.

(generated image for illustration only)

Polymorphism, from Greek for “many shapes,” allows objects of different classes to be treated as objects of a common superclass. It enables a single interface, such as a method name, to be used for a general class of actions. The specific action is determined by the exact type of the object at runtime. This is often achieved through method overriding.

Polymorphism is a powerful concept that allows for writing flexible and decoupled code. The most common form in OOP is subtype polymorphism, which is enabled by inheritance and method overriding. When a subclass provides a specific implementation for a method that is already defined in its superclass, it is called overriding. A variable of the superclass type can refer to an object of any of its subclasses. When a method is called on this variable, the version of the method that gets executed is the one belonging to the object’s actual class, not the variable’s type. This decision is made at runtime, a process known as dynamic dispatch or late binding.

For example, consider a superclass ‘Shape’ with a method ‘calculateArea()’. Subclasses like ‘Circle’ and ‘Rectangle’ can inherit from ‘Shape’ and provide their own specific implementations of ‘calculateArea()’. A program can then have a list of ‘Shape’ objects, containing both ‘Circle’ and ‘Rectangle’ instances. When iterating through the list and calling ‘calculateArea()’ on each element, the correct formula will be used for each shape automatically. This eliminates the need for long ‘if-else’ or ‘switch’ statements to check the type of each object, leading to cleaner, more extensible code. New shapes can be added to the system without modifying the code that processes them.

UNESCO Nomenclature: 1203
– Computer science

Type

Abstract System

Disruption

Incremental

Usage

Widespread Use

Precursors

  • the concept of function pointers in languages like c
  • generic programming concepts
  • inheritance, which provides the class hierarchy necessary for subtype polymorphism
  • the need for flexible and extensible software systems

Applications

  • drawing different shapes (‘circle’, ‘square’) using a single ‘draw()’ method call
  • processing various document types (‘pdf’, ‘word’) with a generic ‘print()’ function
  • implementing user interface event handlers
  • generic collections that can hold objects of different but related types
  • dependency injection frameworks

Patents:

NA

Potential Innovations Ideas

Due to scrapping bot traffic, currently more than 40k per day, this content is reserved to community members.
> Login < or > Register < (100% free) to access this, so as all other restricted content and tools.

Related to: polymorphism, overriding, dynamic dispatch, late binding, subtype, interface, abstraction, oop, method overriding, runtime.

Historical Context

Polymorphism (programming)

1956
1960
1967
1967
1970
1970
1970
1953
1960
1960
1967
1970
1970
1970
1970

(if date is unknown or not relevant, e.g. "fluid mechanics", a rounded estimation of its notable emergence is provided)

Related Invention, Innovation & Technical Principles

Full size images and downloads are only available, 100% free, for registered members.

> Login <