On Nov 5, 10:43 pm, Baishampayan Ghose <b.gh...@gmail.com> wrote: > > Okay, I'm trying to understand records. I read this article: > >http://freegeek.in/blog/2010/05/clojure-protocols-datatypes-a-sneak-p... > > (Clojure Protocols & Datatypes - A sneak peek by Baishampayan Ghose. I > > found it helpful, but the usage of datatypes and protocols looks/feels > > very object-oriented to me. Am I wrong? Is it just because the > > function comes before the record instance? > > > (fly hummingbird) > > > As opposed to calling: > > > hummingbird.fly() in a standard OO language. > > Records & Protocols are indeed a way of achieving polymorphism and is > quite similar to class-based single dispatch found in Java, etc. Thus > the calling conventions can look quite familiar. > > Having said that, records & protocols are fundamentally different from > class based OO since unlike classes, records & protocols don't > complect state and abstractions. > > In your standard OO example, the state as well as the abstraction > method implementations "reside" in the hummingbird object. In case of > Clojure the state is provided by the record/datatype and the method > implementations are provided by the protocols which the record type > chooses to extend.
Even more so, the value, state, *and* polymorphism "reside" in the hummingbird object (as do a number of other things). With records and protocols, the values live in the record; the polymorphism lives in the protocol; and the state (if any) lives in whatever reference type you use. Clojure takes the many, many features that classes and objects typically have, and separates them each into their own place: composable where useful, but fundamentally separate. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en