https://github.com/howprogrammingworks/polymorphism
https://github.com/howprogrammingworks/polymorphism
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/howprogrammingworks/polymorphism
- Owner: HowProgrammingWorks
- License: mit
- Created: 2020-02-02T21:46:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-11-02T21:53:59.000Z (9 months ago)
- Last Synced: 2025-11-02T23:21:08.988Z (9 months ago)
- Language: JavaScript
- Homepage: https://youtube.com/TimurShemsedinov
- Size: 38.1 KB
- Stars: 1
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polymorphism
## Polymorphism classification
1. Ad-hoc polymorphism - Functions or operators behave differently based on argument types
- Function and method overloading - Multiple functions with same name, different signatures
- CSharp example: [`1-ad-hoc.cs`](Classification/1-ad-hoc.cs)
- JavaScript emulation: [`2-emulation.js`](Classification/2-emulation.js)
- Operator overloading - Custom behavior for built-in operators: [`3-operator.cpp`](Classification/3-operator.cpp)
- Type-class polymorphism - Ad-hoc polymorphism via type constraints (e.g. Haskell type classes, Rust traits)
- Coercion polymorphism - Implicit or explicit type conversions: [`4-coercion.js`](Classification/4-coercion.js)
2. Subtype polymorphism - Objects of derived types can be used where base types are expected
- Class inheritance - IS-A relationship via base classes: [`5-abstract.ts`](Classification/5-abstract.ts)
- Interface / protocol polymorphism - Contracts that types must implement: [`6-protocol.js`](Classification/6-protocol.js)
- Structural (duck typing) polymorphism - Compatibility based on structure, not explicit inheritance: [`6-protocol.js`](Classification/6-protocol.js)
3. Parametric polymorphism - Code written generically to work with any type
- Generic functions - Functions parameterized by types: JS [`9-generics.ts`](Classification/9-generics.ts)
- Generic data structures - Data structures parameterized by types: JS TS [`a-generics.js`](Classification/a-generics.js)
4. Dispatch mechanisms - How the runtime selects which method to call
- Dynamic dispatch - Method chosen at runtime based on object type: [`7-dynamic.js`](Classification/7-dynamic.js)
- Virtual functions and methods - Base class methods overridable by derived classes: [`8-virtual.cpp`](Classification/8-virtual.cpp)
- Multiple or multimethod dispatch - Method chosen based on multiple argument types