Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Polymorphism (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementation aspects== ===Static and dynamic polymorphism=== {{Further|Static polymorphism|Late binding|Dynamic dispatch}} Polymorphism can be distinguished by when the implementation is selected: statically (at compile time) or dynamically (at run time, typically via a [[virtual function]]). This is known respectively as ''[[static dispatch]]'' and ''[[dynamic dispatch]],'' and the corresponding forms of polymorphism are accordingly called ''static polymorphism'' and ''dynamic polymorphism''. Static polymorphism executes faster, because there is no dynamic dispatch overhead, but requires additional compiler support. Further, static polymorphism allows greater static analysis by compilers (notably for optimization), source code analysis tools, and human readers (programmers). Dynamic polymorphism is more flexible but slower—for example, dynamic polymorphism allows [[Duck typing|duck typing]], and a dynamically linked library may operate on objects without knowing their full type. Static polymorphism typically occurs in ad hoc polymorphism and parametric polymorphism, whereas dynamic polymorphism is usual for subtype polymorphism. However, it is possible to achieve static polymorphism with subtyping through more sophisticated use of [[template metaprogramming]], namely the [[curiously recurring template pattern]]. When polymorphism is exposed via a [[Library (computing)|library]], static polymorphism becomes impossible for [[dynamic libraries]] as there is no way of knowing what types the parameters are when the [[shared object]] is built. While languages like C++ and Rust use [[monomorphization|monomorphized]] templates, the [[Swift programming language]] makes extensive use of dynamic dispatch to build the [[application binary interface]] for these libraries by default. As a result, more code can be shared for a reduced system size at the cost of runtime overhead.<ref>{{cite web |last1=Beingessner |first1=Alexis |title=How Swift Achieved Dynamic Linking Where Rust Couldn't |url=https://gankra.github.io/blah/swift-abi/}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)