On 22 Jan 2011, at 02:38, Rick Moynihan wrote:
> Well objects are not really a well defined term. However I'd think of
> an object being data + behaviour (methods), where both the data and
> behaviours move around together.
There's (yet another...) definition of OO in the video interview Ralph Johnson,
Joe Armstrong on the State of OOP[1]. I think of OO as more about messaging
and behaviour than data, but then, I can't say I've written OO code without
encapsulating the data behind a layer of messages.
I'll try to watch the Rich Hickey talk soon and rethink this :-)
> I'm not that familiar with Scheme
> (and want to read the wizard book again), but my understanding of what
> is happening above is that the 'objects' are created out of functions
> sharing closures. The same is possible in Clojure, and any language
> with Closures, e.g, here two functions share a closure over an atom
> holding an integer, this is a strong form of encapsulation.
>
> (defn create-obj []
> (let [i (atom 0)]
> {:add-one (fn [] (swap! i inc))
> :sub-one (fn [] (swap! i dec))}))
>
> (def a (create-obj))
>
> ((a :add-one)) ; => 1
> ((a :add-one)) ; => 2
> ((a :sub-one)) ; => 1
Thanks for the example - neat use of the dictionary and double invocation!
>> I'd like to know if Clojure uses a similar convention for OO or if it does
>> something different.
>
> The code above is obviously workable, and occasionally you might see
> things like that, but Clojure isn't an OO language and doesn't really
> want to be. Instead Clojure lets you choose the features of OO
> independently, allowing you to pick'n'mix as you please:
>
> - Polymorphism
> - Identity
> - State
> - Namespaces
> - Hierarchy
>
> Rich Hickey argues that conflating all these notions inside one (or
> two) language construct (the object) (and the class) often has
> undesirable consequences, and that they're more useful independently.
> Having used Clojure, I'd agree :-)
I haven't used Clojure yet, so I can't comment. But I'd be interested to try
it to see how it breaks these concepts apart. I might stalk you all at the
next Clojure Dojo :)
Cheers
Ash
[1] http://www.infoq.com/interviews/johnson-armstrong-oop
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
--
You received this message because you are subscribed to the Google Groups
"NWRUG" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nwrug-members?hl=en.