by pvdebbe · 10y ago · 0 comments
* clojure protocols map to interfaces (abstract classes for C++ folks)
* one can define records that satisfy protocol(s). This is one way to do OO in clojure, happens to map to the underlying JVM mechanisms for JVM optimizations to kick in.
* Gamma et al., Bloch and many others tell to prefer composition over inheritance. Clojure makes this guideline easy to follow.
* overall the OO leaders also recommend making classes "value classes" (everything immutable; smart copy semantics; etc) as often as humanly possible.
* Multimethods allow arbitrary dispatch (most versatile kind of polymorphism) and there is also a faster method when you only want to dispatch by protocols (the (sadly) 'usually' only way to dispatch in most OO languages) that reuses JVM notion of classes and interfaces behind the curtains.
* What you don't get is encapsulation, (and many, a great many authors cite encapsulation to be the definite trait of an OO language,) it can also be argued that immutable values do not need encapsulation per se. A value should be able to stand on its own, convey the semantics it needs & so on..
Yes this is what I was referring to, Clojure is not OO in the way that many think of OO.
But your other points are right on.
Now there forms many schools of opinion, and in many of them it suffices to have data immutable and value-like, and suddenly it doesn't matter if the information is hidden into opaque memory addresses or not.