Woops, Sam beat me to it, so pick your poison... His very well thought
out and quickly typed build-a-human example... or my slowly mashed
together A->F hand-waving :)

On Sep 11, 5:44 pm, "Sam Berlin" <[EMAIL PROTECTED]> wrote:
> Consider an existing chain of objects, something like...
>   Group
>     contains List<Person>
>   Person
>     contains Head[, Body, Arms, Legs]
>   Head
>     contains Eyes[, Ears, Nose, Hair]
>
> Let's say you have want to add an attribute to eyes and want that
> attribute to be shared among each person in the group (maybe they're a
> family and have shared genes).  If you want to the eyes of each person
> in the group to know the GenePool, then doing this by hand would
> require that you
>  a) Construct the Group with a GenePool so that you can
>     construct a Person with a GenePool so that you can
>     construct a Head with a GenePool so that you can
>     construct the Eyes with the correct GenePool.
> or
>  b) Have some static accessor somewhere that Eyes calls out to (a
> service lookup)
>
> On the contrary, if you do this through non-hand-coded DI then the
> objects are constructed for you with only the dependencies they
> directly need to have.
>
> That is the main difference between hand-coded DI & a DI library such
> as Guice or Spring.  When you hand-code DI, you necessarily need to
> pass dependencies through each parent class, even if that parent class
> doesn't need the dependency directly.  Library-guided DI allows your
> objects to only care about their direct dependencies.
>
> Sam
>
> On Thu, Sep 11, 2008 at 8:28 PM, Pyrolistical <[EMAIL PROTECTED]> wrote:
>
> > I have watched that, and I don't see why DI by hand is any worst than
> > Guice.  Its solves all your main problems with testability.
>
> > The ClientFactory in your DI by hand example is very similar to a
> > Provider in a Module for the Injector.
>
> > So how is Guice any better than DI by hand?
>
> > On Sep 11, 5:17 pm, "Bob Lee" <[EMAIL PROTECTED]> wrote:
> >> On Thu, Sep 11, 2008 at 5:10 PM, Pyrolistical <[EMAIL PROTECTED]> wrote:
>
> >> > This is my point.  If using new breaks Guice, then what's the point of
> >> > Guice.
>
> >> > If I need to pass an Injector around to create classes, why don't I
> >> > just pass in the dependencies when I use the new constructor?  I can
> >> > just replace the Injector with a class that holds references to my
> >> > dependencies.  I would create this class at main just like configuring
> >> > a module.
>
> >> > If I did that, what's the point of Guice?
>
> >>http://crazybob.org/2007/06/introduction-to-guice-video-redux.html
>
> >> Bob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to