3 ms·
Polymorphism is not at all specific to OOP, and there are in fact different kinds of polymorphism; "generics" are pervasive in pure FP languages such as Haskell
by ryandv 3y ago
Polymorphism is not at all specific to OOP, and there are in fact different kinds of polymorphism; "generics" are pervasive in pure FP languages such as Haskell or imperative/functional languages like Rust, and are an instance of parametric polymorphism. Ad-hoc polymorphism, or "operator overloading," can also be seen in both languages as the "Eq" typeclass/trait and the equality operator `==`. It's subtype polymorphism and deeply nested inheritance structures that are maybe particular to OOP.
It's also worth making a distinction between an abstract data type - a "thing" and some set of operations defined over it - and a data structure - a particular in-memory construction and set of procedures defined over it, often used to realize an abstract data type. An example being a dictionary ADT - supporting get, set, delete, etc. being realizable through different data structures; for example, a linked "association list" of (key, value) pairs vs. a hash table - with each having different performance characteristics, despite possessing the same properties as the ADT they implement.
- adrian_b 3y agoPolymorphism that is resolved at run-time, i.e. "virtual" functions is what is specific to OOP. The term "polymorphism" was first used in the documents of the language CPL (in mid sixties), the source of BCPL, where in British English it corresponded to what in the American documents of the same age, starting with McCarthy, were called overloaded operators and overloaded functions. The use of "polymorphism" mostly for the run-time polymorphism of OOP languages has appeared only a couple of decades later, with Smalltalk. "Generic", which might be a better term than both, has been popularized during the programming language contest that has lead to Ada (1979). Nowadays it is mostly used for polymorphism/overloading that is resolved at compile time, because this is how the term has been used in Ada.
- ryandv 3y agoEven still, there exist non-OOP implementations of runtime dynamic dispatch, such as Clojure's multimethods.
- ykonstant 3y agoI thought Julia's multiple dispatch was run-time polymorphism?
- mostlylurks 3y agoEven polymorphism that is resolved at run-time is not specific to OOP. In fact, it's used quite extensively outside of OOP, including in both functional and procedural programming. Even ignoring the types of dynamic polymorphism present in other paradigms that might be called "OOP-inspired", there are commonplace patterns such as the use of closures that let you achieve run-time polymorphism and data encapsulation.
- augustk 3y agoWhat you call an abstract data structure is what I have learned is called a concrete data type. To my understanding an abstract data structure is a module with global (single instance) private data which is manipulated using the module's interface. In OOP terminology it's a singleton class.