Jump to content

Runtime polymorphism

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fmadd (talk | contribs) at 05:00, 12 June 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

in computing, runtime polymorphism is polymorphism resolved dynamically based on runtime information. This contrasts with compile time polymorphism.

Approaches

Different systems exist for implementing runtime polymorphism with various tradeoffs in performance and flexibility:-

Single dispatch

  • in the C++ programming language, vtables embedded in each object instance are used to select behaviour. Compiled code needs to know a base class vtable format and data layout in order to use any derived type. Multiple inheritance is also possible, implemented via internal double indirection to access different base class members.
  • in Go and Rust, vtable pointers are carried with object references as 'fat pointers' ('interfaces' or 'trait objects'). This decouples the supported interfaces from the underlying data structures; each compiled library needn't know the full range of interfaces supported in order to correctly use a type, just their required vtable layouts.

Late binding

Multiple dispatch