You can reuse methods by putting them in a map and then just merging it
with the new methods:
(extend Employee
AProtocol
(merge default-implementation {:new-function (fn ...)}))
The problem is that you can't reuse methods defined inline, i.e. you can't
say "my record implements this protocol just like that other record".
воскресенье, 20 мая 2012 г., 23:22:55 UTC+6 пользователь Warren Lynn
написал:
>
> So from what I read the philosophy of Clojure discourages inheritance
> on concrete data types. However, maybe I am too entrenched in my OO
> thinking, how do I define a new record type that includes all the data
> members of another record type? I am thinking about the classic
> Employee/Person example.
>
> If I can define a record of Employee with Person's data members
> included, even that is not true inheritance (as no protocols of
> "Person" will be automatically extended to "Employee"), I need that
> for function re-use (so a function working on Person will
> automatically work on Employee because Employee is guaranteed to have
> all the data members in Person).
>
> Also, again, maybe I am too OO minded, is there a way inherit another
> record type's protocol implementation? That seems to give the best
> combination of both worlds (OO and functional), so you can either have
> you own very customized combination of data type/protocols, or use the
> very common OO pattern. Just like we have both the single-typed
> dispatching (which is more OO like and covers a large portion of use
> cases), and more advanced multimethods.
>
> Thanks.
--
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