I read too quickly. I might need multi-methods after all, just like I used
in Common Lisp. I want different types of persisted objects to have the
same interface, if possible.
Actually, I'm just experimenting with protocols, so I'm probably better off
looking for a different use case.
On Mon, Aug
Makes perfect sense. Thanks!
On Mon, Aug 29, 2016 at 5:09 PM Jonathan Fischer
wrote:
> The most straightforward one: just make your protocols a thing that your
> storage medium implements, instead of your records. E.g.:
>
> (defprotocol ThingStore
> (load-item [store item-id])
> (load-items
The most straightforward one: just make your protocols a thing that your
storage medium implements, instead of your records. E.g.:
(defprotocol ThingStore
(load-item [store item-id])
(load-items [store item-ids])
(find-item [store item-name])
(save-item [store item]))
(defrecord Databas
Two options. The first, straightforward one: make the thing that's
implementing the protocol the Storage, not in the individual things being
stored. So something like:
(defprotocol ItemStore
(save-item [store item])
(load-items [store items]))
etc.
Second option: Clojure has multimethods t
Considering the regular use-cases with records:
Create - requires record without any auto-generated identifiers
Retrieve - requires primary identifier or lookup parameters
Update - requires record with primary identifier and updated fields
Delete - requires primary identifier or lookup parameters
I'm beginning a foray into protocols after coming from the Common Lisp
world of multimethods. I'm using them initially to implement a consistent
load/save API over the DB layer.
It's pretty simple to have a Saveable protocol to save one object, because
the first argument is a Record of the type