On 19 January 2014 19:55, Brian Craft <[email protected]> wrote:
> http://www.youtube.com/watch?v=ROor6_NGIWU
>
> Around 56:28 Rich is talking about whether components pass a data
> structure, or "an object that has all these verbs and knows how to do stuff
> ...".
>
> Clojure data types also have verbs, in protocols, and if one component
> passes a record to another component, the receiver will need to use those
> verbs to make use of the data. How is that different than the OOP example?
> There's the syntactic difference that in OOP you write it object, verb,
> arguments, and in clojure you write it verb, object, arguments. But that's
> trivial. How is it architecturally different to pass an object with methods
> vs passing a record with protocol?
>
Protocols should be considered a tool for polymorphism, rather than a tool
for encapsulation. You shouldn't consider protocols to be tightly coupled
to a record or type.
To give a more concrete example, consider a edn data structure like:
#inst "2014-01-19T21:44:46.471-00:00"
By default Clojure reads this as a java.util.Date object, but we could
equally read this as a org.joda.time.DateTime object, or
a hirondelle.date4j.DateTime object.
All these implementations describe the same data, but will have subtly
different methods and interfaces. The data structure serialised in edn
doesn't mandate a particular class, or a particular set of methods.
Similarly, if we imagine a data structure like:
#myapp/Person {:first "Fred" :last "Mertz"}
You should think of this as a map tagged with "#myapp/Person", not a
representation of a specific Clojure record that has a specific set of
functions. It's up to the receiver to interpret this data, and the
functions that operate on this data might differ between components. For
instance, a component that displays the data to the user might have a
function to derive a person's full name, but a component that archives the
data wouldn't need this functionality.
- James
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.