On Wed, Mar 28, 2012 at 8:46 PM, Chris McBride <cmm7...@gmail.com> wrote:
> I'm not trying to do anything in particular. I do OO programming at work and 
> it's been pounded in my head that loose coupling is better than gift 
> coupling. I've found it useful on a few occasions. One example, in the 
> frontend we wrap all the database calls in a caching layer but we don't need 
> that when the same code runs in the backend. I wouldnt know how to do this 
> with clojure.

A higher-order function, I should think, so you have something like

(defn basic-retrieval-fn [query & opts] ...)

(def caching-retrieval-fn (some-sort-of-fancy-memoize basic-retrieval-fn))

(defn do-something [conn query retrieval-fn mumble frotz] ...)

Or maybe a dynamic bind:

(def ^:dynamic *retrieval-fn* caching-retrieval-fn)

Or even a configuration file:

(defn get-retrieval-fn []
  (let [blah blah blah (Properties. +config-file+) blah blah]
    (if foo caching-retrieval-fn basic-retrieval-fn)))

or even

(defn get-retrieval-fn []
  (let [symb (with-open [in (open-config-file)] (symbol (first (line-seq in))))]
    (resolve symb)))

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