3 ms·
OO is more general than that, it's just a general paradigm for code reuse. Polymorphism is one of many forms of code reuse (allowing functions to accept multipl
by kyllo 12y ago
OO is more general than that, it's just a general paradigm for code reuse. Polymorphism is one of many forms of code reuse (allowing functions to accept multiple type signatures). I wouldn't call it the "central point" because polymorphism can be done without OOP, and OOP can be done without polymorphism.
- kaonashi 12y agoWhat you're saying is that traditional OO conflates polymorphism with encapsulation and inheritance, creating one big complexity murder-death-ball; whereas Haskell lets you have these things a-la carte, so you can deploy them as needed.
- pjmlp 12y agoIt is central. Without polymorphism you don't have a way to abstract algorithms over types. So you just get ADTs as introduced by Mesa/Modula-2.
- kyllo 12y agoYou can do OOP with only ad-hoc polymorphism, which is just method overloading, which is what Java and C++ do. Actual parametric polymorphism isn't necessary for OOP, and there are non-OOP languages that have it (e.g. SML has polymorphism but does not have objects). So, polymorphism and object-orientation are orthogonal concerns. OOP is about encapsulation, inheritance, and modules that couple mutable state (attributes) and behavior (methods).
- agumonkey 12y agoFor the curious, Ocaml mixes both, its object model is parametric (see: http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html)
- pjmlp 12y ago> You can do OOP with only ad-hoc polymorphism... Which is still polymorphism. I purposely did not enumerate all CS forms of polymorphism, but can get more detailed if you will.