Hi All,

In the course of putting together my latest piece of work I decided to
really embrace TDD. This is run of the mill for me in Java:

- create some object that models your flow
- create some object which contains your storage logic
- create tests
- dependency inject the correct storage logic depending on which scenario
you're running in (prod / test / etc).

I've not been able to think about how to correctly achieve this same
functionality in clojure.

So far everything is pretty much pure functions, the storage functions being
the only place where data is changed. Currently the storage is implemented
with atomic maps. The production storage will be in Riak.

I'm getting ready to build the Riak backend and now I'm faced with how to
choose the correct backing implementation. I've a namespace,
rah.test-storage, which implements the in-memory storage and I anticipate
putting riak storage in rah.riak-storage - however I'm not sure what the
best way to select the correct implementation at runtime or test time is.

One solution I've come up with is to use defprotocol to define the functions
for the storage layer (as you would an interface in java) and then have a
defrecord for each implementation. Assume these to be in the namespace
rah.storage, which would also house the functions which call the correct
defrecord functions based on a property given at start time.

This solution, however, feels like me trying to write Java in clojure - and
I'm wondering how the lispers of the world would solve this same issue.

Another solution would be to write the same set of functions in the
rah.storage namespace which then look at the same property and then decide
whether to call rah.riak-storage/store-user! or
rah.test-storage/store-user!.

Any thoughts much appreciated.

Cheers,

mike

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