This article was originally published on bmf-tech.com.
Overview
Summarizing polymorphism
What is Polymorphism
- Poly (multiple) Morphism (forms)
- Providing a shared interface for multiple different types
- Instances behave differently depending on the class when receiving arguments
Types of Polymorphism
- Ad-hoc polymorphism
- Functions have different implementations for arguments of different types
- Achieved through overloading and function overloading
- Parametric polymorphism
- Code is written without specifying types and can be used transparently for each type
- Applicable to various types by passing the type as an argument
- Achieved through generics or templates
- Subtyping
- Handling multiple types with a common supertype under a single name
Top comments (0)