Maybe a twisted and simplified variation on a pattern called the Object Pool 
can help here.

ie you have a pool of child objects.

You can either:

a) When app starts create all the child objects and store references to them in 
the Pool (ie in its variables.instance scope - think of it as a cache)
b) lazy load them when they are asked for (recommended)

I'll use an example of music albums and tracks. A track can appear on different 
albums so a MusicTrackObjectPool can deal with tracks.

When a track is requested we would use: 

objPool = mySingletonFactory.getBean("musicTrackObjectPool");
fluffyClouds = objPool.getTrack("Little Fluffy Clouds") // you would probably 
use an identifier here like a db pk

the pool would check if the track exists in its cache (variables.instance 
maybe) and if not do a createObject, populate the object, cache a reference to 
it then return it to the caller.

This way the Pool fills up over time.

It would also have helper methods like emptyPool() that clears the cache, 
objectExists() that checks if a reference to an object has been cached etc

Think of it as a factory that only deals with one blueprint of object. It's 
also simpler than the classical Object Pool pattern as it doesn't have a finite 
amount of objects to manage with a maximum threshold. 

Obviously to use this you need to have either a small amount of possible 
objects OR a large amount of server memory if there are many objects.

 Alan




________________________________
From: Henry <[email protected]>
To: CFCDev <[email protected]>
Sent: Wednesday, February 11, 2009 7:29:44 AM
Subject: [CFCDEV] Re: Implementation of composition pattern, help.



> > 2.  If the child object is shared by more than 1 parent, should the
> > parent all reference to the same instance of the child object?  If so,
> > how?
>
> > Possible implementation:
> > - Storing a struct of child objects by ID in Application scope?  That
> > sounds bizarre and wrong
> > - Factory pattern with cache layer??
>
> > If not, then the updated child might be overwritten by an old child by
> > another parent object. e.g.
> > Parent A @ init'ed, has copy of Child1, Child1.name = "ONE"
> > Parent B @ init'ed, has another copy of Child1, Child1.name = "ONE"
> > Parent A update Child1's name to TWO
> > Parent A save (Child1 saved, Child1.name == TWO)
> > Parent B save (Child1 saved, Child1.name == ONE)
>
> Yes, there should only be one instance of the same concrete object at a
> time, or you'll run into a storm of synchronization issues. Which means some
> central cache is required to ensure duplicate objects are not created.

How would I implement that "central cache"?  Factory with cache
layer?  How to determine how many objects to cache?  Do I need to
implement a stack of Most Recently Used objects in CF? wow, this is
really getting complicated.


      
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CFCDev" 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/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to