I believe the protocol's analogue for get-method would be enough.

вторник, 3 июля 2012 г., 2:58:49 UTC+6 пользователь Warren Lynn написал:
>
> When I re-read the thread "defrecord with inheritance"
>
> https://groups.google.com/forum/?fromgroups#!searchin/clojure/inherit/clojure/mr-o9sRyiZ0/oM4zRz4dXYsJ
>
> I am thinking: conceptually, for code reuse, is it a good idea to have 
> protocol specific type hierarchy? I mean something like this:
>
> (defrecord a [x y z])
> (defrecord b [x y z])
> (defprotocol p (foo [this] "Hi"))
> (record-derive b a p) 
>
> So the above means, when protocol "p" is concerned, type "a" is the parent 
> for type "b", and any implementation of "a" of "p" applies to "b" if "b" 
> does not have its own implementation. This is similar to type based 
> dispatching in multimethod, but right now it seems "(derive b a)" is not 
> allowed with record as the parent.
>
> I believe inheritance is not bad, but the traditional OO way fixes the 
> hierarchy from one pre-designated perspective hence cause trouble when you 
> need to look at things from another perspective.
>
> Right now the protocol actually already works on build-in Java hierarchy. 
> Example:
>
> (defprotocol testp (foo[this]))
> (extend-protocol testp clojure.lang.PersistentVector (foo [this] 
> "PersistentVector impl"))
> (extend-protocol testp clojure.lang.Seqable (foo [this] "Seqable impl"))
> (foo []) => "PersistentVector impl"
> (foo '()) => "Seqable impl"
>
> I have no idea if the above is implementable. Any comments?
>
>
>

-- 
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

Reply via email to