9 ms·
The essence of OOP is not inheritance, that’s a nice to have. The essence of OOP is to encapsulate the data and the functions that operate on that data into an
by Hermel 5y ago
The essence of OOP is not inheritance, that’s a nice to have. The essence of OOP is to encapsulate the data and the functions that operate on that data into an object and hide the internal state of the object from the rest of the program.
- ncmncm 5y agoOO less inheritance has a different name: object-based. It isn't better or worse. But the distinction is worth keeping.
- chriswarbo 5y agoIf this is the essence of OOP, would you consider modules/existential-types in StandardML to be OOP? As a followup, what about OCaml (is that "more OOP"?)
- jcelerier 5y agoML modules are definitely OO
- c-cube 5y agoSee, that's just ridiculous and shows how undefined and vague "OO" is. The only relevant feature there is encapsulation, that most languages provide in some way. How is that OO? I vote for just not using this term anymore and talk about class based langusges or prototype languages or whatever.
- mypalmike 5y agoThe problem isn't that the term is poorly defined. It's that it's widely misused. Dynamic dispatch (basically "inheritance") is what most experts claim to be the defining feature necessary to claim OO.
- jcelerier 5y ago> The only relevant feature there is encapsulation, that most languages provide in some way. How is that OO? PL researches seem to have no trouble finding equivalences between ML modules and OO : https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.53.5372&rep=rep1&type=pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.53... My personal opinion which tries to be as general as possible to encompass most definitions is that OO just means that semantic entities can bind a set of named values with a set of named operations / functions / methods / whatever you call them. struct foo { int bar; void (*compute)(int x, int y); }; is also OO.
- throwaway894345 5y agoEvery OO proponent seems to have their own definition of OO. Another I’ve heard is “message passing”, although that one even has many different flavors since it isn’t well defined and some argue that methods constitute message passing and others envision something closer to an Actor model. This is all well and good as long as people are clear about what their definition is (although it is weird how many proponents have wildly different definitions and yet still seem to feel some kind of kinship). The maddening folks are those who deflect all criticism of OOP by saying “that’s not true OOP without ever asserting any particular definitional qualities. These people seem to have an undying love for the sequence of letters O-O-P. So we have these weird conversations where I say, “fine, I contend that anything that might make OOP unique from other paradigms (e.g., inheritance) is a misfeature”.
- cout 5y agoThe concept of a message is older than the actor model, so I don't think it can be considered a fundamental part of the definition of a message (so Smalltalk-style messages are still messages). I do think the Actor model is the most ideal form of message-passing in a single-process system, and seems to be the direction many languages are heading toward as they evolve.
- throwaway894345 5y agoTo be clear, I’m saying “something like the actor model”, not the actor model specifically, though I assume the actor model also satisfies even the narrower definitions of message passing.
- Rochus 5y ago> The concept of a message is older than the actor model Publications by Hewitt or Sussman in the seventies even suggest that the concept traces back to lambda calculus. > so Smalltalk-style messages are still messages Only Smalltalk-72 had true "message passing" (i.e. arbitrary tokens sent to an object for interpretation); Smalltalk-76 onwards uses a virtual methods implementation similar to the one of Simula 67 or C++ instead.
- rualca 5y ago> The essence of OOP is not inheritance, that’s a nice to have. The essence of OOP is to encapsulate the data and the functions that operate on that data into an object and hide the internal state of the object from the rest of the program. What is inheritance but a way to encapsulate data and methods in a way where you only need to override a subset of very specific methods and/or data to specialize an implementation?
- ratww 5y agoInheritance is a bit more complicated than that. Your definition is closer to what the Template Method pattern [1] is, rather than inheritance in general. Keep in mind also that neither inheritance itself nor the Template Method pattern guarantee encapsulation. [1] https://en.wikipedia.org/wiki/Template_method_pattern https://en.wikipedia.org/wiki/Template_method_pattern
- barrkel 5y agoI would say that polymorphism open to extension is also important, and subtype / supertype hierarchy. It implies some kind of composition of interface types in a static language.
- andi999 5y agoWhile data encapsulation sounds like a nice feature in theory, it seems to be the actual biggest flaw.
- kaba0 5y agoHow is it a flaw? There are data-first processes where a LISP-style data “objects” are better, but there are many stateful objects, eg. a database connection where you very much don’t want anyone to access a flag with this specific meaning or IP or secrets, etc.
- mariodiana 5y ago"OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late binding of all things." – Alan Kay
- ratww 5y agoThat's a great definition, but it mostly applies only to Smalltalk itself and a subset of Smalltalk descendants, like Ruby. EDIT: changed ancestor to descendant, thanks gnufx!
- gnufx 5y ago[s/ancestor/descendent/] Not Erlang (maybe depending on whether you consider something like Armstrong's universal server extreme late binding)?
- ratww 5y agoGood question! Alan Kay himself definitely thinks so: https://www.quora.com/What-does-Alan-Kay-think-about-Joe-Armstrong-claiming-that-Erlang-might-be-the-only-object-oriented-language-and-also-his-thesis-supervisor-s-claim-that-Erlang-is-extremely-object-oriented https://www.quora.com/What-does-Alan-Kay-think-about-Joe-Arm...
- mypalmike 5y agoI'd say most of these attributes map pretty well to modern OO practices in popular languages, particularly Java, where late binding comes from widely used inversion of control frameworks like Spring. And the underlying mechanism for these is dynamic method dispatch, which I'd agree with Robert Martin is the single unifying requirement of OO.
- layer8 5y agoLanguages without inheritance/subtyping are normally called object-based [1], in distinction from object-oriented. [1] https://en.m.wikipedia.org/wiki/Object-based_language https://en.m.wikipedia.org/wiki/Object-based_language
- augustk 5y agoWhat you describe is the essence of an abstract data type (ATD). An ADT can be easily implemented in a non-object oriented language like C. To my understanding the essence of object oriented programming is inheritance and polymorphism.