You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by Anil Gangolli <an...@busybuddha.org> on 2007/05/20 18:16:50 UTC

DI and singletons

I notice that I had missed the entire thread about Guice on this list before seeing the commit go by and commenting on that.

I also noticed a discussion of singletons.  One of the lessons I've learned from using DI is that the notion of singleton is best not inherently represented in the code, but rather just as an artifact wiring up one instance of a dependency to be used by a set of other objects.  A class should not care if there is one instance of it or than one instance of it around; it can just deal with its members.  This also tends to clarify the abstraction of what the singleton is doing and open things up; sometimes you find that you want to allow for different implementations.

--a.


Re: DI and singletons

Posted by Anil Gangolli <an...@busybuddha.org>.
I somehow mangled the message while editing.  I meant to say:

"... an artifact of wiring up one ..."

"A class should not care if there is one instance of it or more than one 
instance of it around..."

----- Original Message ----- 
From: "Anil Gangolli" <an...@busybuddha.org>
To: <ro...@incubator.apache.org>
Sent: Sunday, May 20, 2007 9:16 AM
Subject: DI and singletons



I notice that I had missed the entire thread about Guice on this list before 
seeing the commit go by and commenting on that.

I also noticed a discussion of singletons.  One of the lessons I've learned 
from using DI is that the notion of singleton is best not inherently 
represented in the code, but rather just as an artifact wiring up one 
instance of a dependency to be used by a set of other objects.  A class 
should not care if there is one instance of it or than one instance of it 
around; it can just deal with its members.  This also tends to clarify the 
abstraction of what the singleton is doing and open things up; sometimes you 
find that you want to allow for different implementations.

--a.