Skip to content
uencoder

Polymorphism

Polymorphism lets the same interface operate on instances of different types, in two forms: static (overloading/generics) and dynamic (overriding/virtual methods).

Purpose

Handle different types through a unified interface, improving code reuse and extensibility.

Mechanism

Static polymorphism: overloading (same name, different parameters) and generics (instantiated at compile time). Dynamic polymorphism: overriding (subclass replaces parent method) dispatched via vtables. Go uses implicitly implemented interfaces; Rust uses trait objects.

Use cases

  • Object-oriented design
  • Interface abstraction
  • Code reuse

Related terms

References