advice on building a factory for transient objects

14 views
Skip to first unread message

Gareth Cole

unread,
Oct 21, 2009, 12:48:24 PM10/21/09
to coldspri...@googlegroups.com

Hi,

 

Strictly speaking, this may not be a coldspring issue, but it seemed like the best place to ask.

 

I use CS to manage all my singleton objects, and it also manages a Reactor factory which creates most of my transient objects.

 

However, now I need to create other transient objects which will perform a form of validation. I'll call the objects AssignmentChecker, and each instance will need to be created and configured differently depending on the circumstances.

 

I reckon the best way to do this is to build a custom AssignmentCheckerFactory, however, I've never built a custom factory before.

Should it be as simple as a single function that creates the AssignmentChecker object, sets stuff according to the function arguments, and returns it? That sounds way too obvious J

If CS manages the factory, will CS be injected into the transient objects too? Or do I need to set this up? Or should I avoid injecting CS unless needed?

 

Any advice would be appreciated.

 

Thanks,

 

Gareth

Chris Blackwell

unread,
Oct 21, 2009, 1:10:11 PM10/21/09
to coldspri...@googlegroups.com
Yeah a factory just does whatever you need it to in order to create your transient object.  
I'd avoid injecting coldspring into the transient, but if the transient needs to use singleton beans from cs then inject those beans.  Take a look at http://coldspringutils.riaforge.org/ specifically the BeanInjector.cfc

Cheers, Chris

2009/10/21 Gareth Cole <garet...@esus.ie>

sipa...@gmail.com

unread,
Oct 21, 2009, 1:22:41 PM10/21/09
to coldspri...@googlegroups.com
Gareth,

The simplest factory is simply a wrapper around a create object call.

I often have factories that get dependencies added in by coldspring, then manually set them into my transients as needed.

You can describe the dependencies in your coldspring configuration, or just have a factory that just assumes dependencies based on the factory type.
This means the product factory creates product transients, and sets the productDAO in every product transient.

What you would do well to avoid is to have your factory talk to coldspring. The factory should not know coldspring exists at all. Any design that has a transient factory with knowledge of the coldspring bean factory is upside down and needs to be rethought on the aspects of encapsulation and information hiding.


Dan


Sent from my Verizon Wireless BlackBerry


From: "Gareth Cole" <garet...@esus.ie>
Date: Wed, 21 Oct 2009 17:48:24 +0100
Subject: [coldspring-users] advice on building a factory for transient objects

Gareth Cole

unread,
Oct 21, 2009, 1:38:38 PM10/21/09
to coldspri...@googlegroups.com

Thanks folks.

 

I've just been getting my head around the beanInjector example in the coldspring utils. That's very clever how it works.

 

At the moment, I don't think my transient objects will need access to any other beans, so I'll keep it simple for now. If they need beans in the future, I'll either get the factory to set them or use the beanInjector.

 

What is likely to happen, is that I cache AssignmentChecker objects in the factory to improve performance. I suppose by keeping their creation within the factory, caching should be easier to implement

Bob Silverberg

unread,
Oct 21, 2009, 2:36:49 PM10/21/09
to coldspri...@googlegroups.com
On Wed, Oct 21, 2009 at 1:22 PM, <sipa...@gmail.com> wrote:
 
What you would do well to avoid is to have your factory talk to coldspring. The factory should not know coldspring exists at all. Any design that has a transient factory with knowledge of the coldspring bean factory is upside down and needs to be rethought on the aspects of encapsulation and information hiding.


Yay, another chance to make a fool of myself and get edumacated in public! The practice that you are suggesting is totally wrong is actually what I'm doing right now, so I'm keen to understand exactly what's wrong with it.  Perhaps what I'm doing doesn't fall into what you're talking about, but it sure sounds like it does.

I have a TransientFactory which makes use of Brian's BeanInjector to wire singletons into Transients. The factory itself has all the knowledge to create the transients, but once they are created it then asks the BeanInjector to autowire them from Coldspring. Each Transient has setters for any singleton that it needs, and the BeanInjector is able to look at those setters and then grab the proper bean from CS and pass it into the setter.  This makes sense to me, because CS remains my single repository for singletons, and the TransientFactory is really kind of like an extension of Coldspring, designed to create transients in a more efficient manner than CS can do it.

The transients have no idea where the dependencies are coming from, and the TransientFactory doesn't either - it simply asks the BeanInjector to do its job.  The BeanInjector most definitely knows about CS, but that's its raison d'etre.

Does that approach contradict the principles of encapsulation and information hiding?

Cheers,
Bob

--
Bob Silverberg
www.silverwareconsulting.com

sipa...@gmail.com

unread,
Oct 21, 2009, 2:55:07 PM10/21/09
to coldspri...@googlegroups.com
I'd say you have an object whose primary objective is to mediate between the coldspring bean factory and transients.

I actually use the same object to inject coldspring singletons into Transfer transients.

The slippery path isn't there, but in cases where a programmer just puts a reference to the coldspring factory in the transient factory.

I don't like that approach because it doesn't specify the dependencies and also creates a gap in the system design. It is always best to be clear about documenting dependencies as it helps maintainability.


DW.

Sent from my Verizon Wireless BlackBerry


From: Bob Silverberg <bob.sil...@gmail.com>
Date: Wed, 21 Oct 2009 14:36:49 -0400
Subject: [coldspring-users] Re: advice on building a factory for transient objects
Reply all
Reply to author
Forward
0 new messages