3 ms·
The essence of OOP is abstraction via message sends to and from an otherwise opaque interface. (Really really close to actors, but message sends are synchronous
by barrkel 8y ago
The essence of OOP is abstraction via message sends to and from an otherwise opaque interface. (Really really close to actors, but message sends are synchronous by default and objects don't have their own thread of control.) That's what gives you polymorphism; inheritance and encapsulation are down to discipline. Often implemented as a table of function pointers for performance reasons, the message sends becoming ordinals into the pointer table, and losing a certain degree of encapsulation and first-classness in their own right, like delegation or queuing or other interesting things.
OOP isn't specifically attached to tying behaviour and data together. But if you only get to interact with state via message sends, and you try and follow that all the way through so your only non-primitive values are objects (and perhaps even your primitive values are objects too), then at least some of those opaque references are going to be mutable. And then you get state into the mix, and trouble starts brewing.
IMO Rust traits, Go interfaces, Java interfaces are the essence of OO.
- didibus 8y agoI mean, yes and no. That's why this is a semantic debate. There are no right or wrong. Paradigms of programming are not formal concepts. Some people say the essence of OOP is polymorphism. Others say it is inheritance. Others say it is the tying together of data and behavior. I personally find issue with saying OOP is just ADTs + polymorphism. Which is what rust traits, go interfaces and java interfaces are. Type A Type B function F(value) { switch(typeof value) { case A: "I am A." case B: "I am B." } } There, I have achieved object oriented programming. I have values with an identity, A or B, and I have polymorphic functions over them. I don't know, it feels too broad to be useful. That's why I prefer to say that OOP is more related to the tying together of data and behavior behind an object. This is how the Gang of Four book defines OO. I find it frames things in a way that is more differentiating. So now I can have OO, inheritance and polymorphism in any combination I want. This means Clojure/Script can now be defined as supporting inheritance and polymorphism, which it does, yet not supporting OO. And I can have another language supporting OO and polymorphism, but not inheritance, such as Rust. Or without OO and inheritance, but with polymorphism like Go, etc.
- pjmlp 8y ago> This is how the Gang of Four book defines OO. That book defines OO from the point of view of Smalltalk and C++.