Even though Dave didn't actually necessarily say to _favor_ Setter over Constructor injection, I tend to agree with Sean in using setter injection when wiring together true collaborators. One thing to think about I suppose is, how would you construct your objects _without_ ColdSpring? Here is where I would often pass objects into init methods, so a point could definitely be made that I am actually tailoring my objects to work with ColdSpring, which is not completely optimal. It is best to have your cfcs really not dependent on ColdSpring in any way. However, real world circumstances end up dictating that I often work with circular dependencies, I prefer the notation of defining properties, and I also prefer to try to create my components in a way that they don't necessarily rely on a bunch of other cfcs just to be instantiated in the first place.

So I guess as Dave is saying, find what is best for your development style and your architecture and remember there are no hard and fast rules here, ColdSpring is simply not that kind of framework!

-Chris



On Jul 18, 2006, at 11:15 AM, Sean Corfield wrote:

On 7/18/06, Perry Woodin <[EMAIL PROTECTED]> wrote:
After setting this up, I went back to look at some of the examples that ship
with ColdSpring and noticed that <property> seems to be used in favor of
<constructor-arg>.  Is there a general rule for when to use one over the
other?

Dave Ross, in his presentation at CFUNITED, said "favor setter
injection over constructor injection".

Setter injection supports circular dependencies, constructor injection
does not (pretty much by definition).

It's better (IMO) to have objects constructed with just the data they
need in order to be usable and then inject everything else. In
general, I only use constructor injection for simple scalar values
(e.g., strings) and use setter injection for more complex properties.
-- 
Sean A Corfield -- http://corfield.org/
Got frameworks?

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


Reply via email to