Hari, First, I'd recommend you watch Rich's videos on Clojure, both for Java programmers and LISP programmers. In it Rich explains why Clojure *isn't* OO. It's heresy to some who has written lots of Java, but once you see Clojure in action, everything starts to make sense. I know when I went down my path (Java->Ruby->CL->Clojure), it took me a while to feel comfortable living w/o objects.
Without knowing your specific problems, I can offer some suggestions on how to get the effects of DI in a much more awesome way in Clojure 1. Understand how to use higher order functions. Here's a few great examples: map reduce filter remove some every comp Notice how these functions take a *function* as one of their arguments. This is a classic case of where Clojure eliminates the need for a DI framework. 2. Learn to curry functions. Suppose you have a function that applies a quadratic equation user=>(defn quad [a b c x] (+ (* a x x) (* b x) c)) user=>(def my-ints (range 1 11)) You can map a specific parabola like so user=>(map #(quad 1 0 0 %) my-ints) (1 4 9 16 25 36 49 64 81 100) Notice how three values were fixed and the last value varied, producing the value you expect. This way we could plot any parabola by changing the value of the inputs. 3. Write functions that generate functions The last example was okay, but it felt a little forced. Let's create a function to do the currying for us: user=>(defn my-parab [a b c] (fn[x](quad a b c x))) Now, it isn't immediately obvious, but my-parab returns a function. user=>(ifn? (my-parab 1 0 0)) true Let's use it in a map user=>(map (my-parab 1 0 0) my-ints) (1 4 9 16 25 36 49 64 81 100) I find that using functions to create functions is a way more powerful factory method that can usually be achieved in Java. They can be combined & layered in ways that Spring can only dream of. 4. Make comp your best friend Being able to actually compose functions is amazing. It lets you write much much much smaller functions, and put them together in wonderful new permutations. ;This squares a value, and then adds .005 (map (comp (my-parab 0 1 0.005) (my-parab 1 0 0) ) my-ints) Notice I didn't even get into macros yet. I hope these examples help get you started hacking Clojure. One more thing, read Stuart Holloway's book. It's great. Sean On Jun 16, 12:18 pm, hari sujathan <hari.sujat...@gmail.com> wrote: > hi Stuart, > > I was trying to look from some mathematical concepts by representing - > OOP's inheritance by tree/graph structurtes(tree for single , and > graph > for multiple inheritence) with classes acting as each node. > With functional programming - nodes are each block of code.. > > Dependency injection means- configuring some parameters into each of > these nodes(whether its class or a piece of code, DI is independent > concept). > I dont know on how to improve, and things I wrote above may just be > wrong(my own thought process). > I just started to read Bertrand meyer's book- "Object Oriented > software construction" which is simply awesome . > > -Hari Sujathan > > On Jun 16, 7:13 am, Stuart Halloway <stuart.hallo...@gmail.com> wrote: > > > Hari, > > > I agree--dependency injection is not about OOP. It is about working > > around limitations in certain languages where it is difficult to > > decouple components for testing and flexible deployment. > > > I have not encountered similar limitations in Clojure. Do you have an > > example in Clojure that makes you wish for DI? I would be interested > > in taking a look and suggesting a more idiomatic Clojure approach. > > > Cheers, > > Stu > > > > Hi, > > > clojure web site says - "Clojure multimethods are a simple yet > > > powerful mechanism for runtime polymorphism that is free of the > > > trappings of OO, types and inheritance" . > > > > I think dependency Injection has nothing to do with just OOP, though > > > it came out in OOP. > > > Why not dependency inject arbitary code to another arbitary code?? > > > > Thanks & Regards, > > > Hari Sujathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---