Joe you made my head hurt then! Hehehe
So, in a nuthsell you have:
You have a series of objects that have their own specific methods (I'm trying not to break into an analogy here).
Then at runtime, based on the context of its use you need these ingredients (objects) to be merged together into one object to form
A perfect virtual object that has specific methods available (while same in naming but can also accepts different arguments). Sounds like an AOK use for the decorater or maybe even a case study for interface! Hehe
(ie analogy time)
I may bake a cake with eggs, flour, milk and no sugar
You may bake a cake with eggs, flour, water and sugar
Yet, the end consumer sees and uses the cake in the same way, only its ingredients underneath has changed?
The only downside I've even found with using decorator is (its hard to debug sometimes, you're methods can conflict with one another if your not careful, making a dynamic virtual object at runtime pieced together from others - just seems abnormal hehehe but it's an alternative approach to multiple inheritance.
Am I on the same page or another tangenet (think the later)?
Regards,
--------------------------------------------------
Scott Barnes
System Development Engineer
Goro Nickel Project
Level 8, 201 Charlotte Street
Brisbane QLD 4000
Email: [EMAIL PROTECTED]
Personal Blog: http://www.mossyblog.com
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]] On Behalf Of Joe Rinehart
> Sent: Tuesday, 11 January 2005 1:27 AM
> To: [email protected]
> Subject: [CFCDev] Cache design using decorators and factories
> - advice/criticism?
>
> Hey folks,
>
> I need a super-generic container in which to keep stuff,
> i.e., a cache. I need to be able to have the cache manage
> its items either based on cache size (can't grow above N
> items), or time (if I ask for an item that's past it's
> expiration, a specialized error is thrown).
>
> My first attempt at this taught me some of the evils of
> over-inheritance - I had a GenericCache that just held stuff,
> with two subclasses - TimedCache and SizedCache. As the
> complication level of some things grew, they got pretty
> unruly: sized cache needed things in the base that timed
> didn't, timed needed things in the base sized didn't, and
> things got tangled.
>
> Now, I've tried to break this apart into a cleaner system
> using decorators and factories. My design consists of the
> following CFCs:
>
> GenericCacheItem - An item in the cache
> GenericCache - decorated by a GenericCacheCollection (or
> subclass) GenericCacheCollection - decorated by a
> GenericCacheCollectionManager (or subclass)
> GenericCacheCollectionManager - single method, cacheContains(key).
> When GenericCacheCollection.get(key) is called, it first
> calls cacheContains(key), which determines whether or not
> the item is still valid, and if not, removes it from the cache
>
> I've built a GenericCacheFactory that builds a
> GenericCacheCollection, decorates it
> GenericCacheCollectionManager, builds a cache, and decorates
> it with the GenericCacheCollection that's just been built.
>
> To enable a sized cache, I subclass GenericCacheCollection
> with SizedCacheCollection, which adds logic to the put()
> method that'll remove the oldest item from the cache if the
> cache is above a maximum size (set in SizedCacheCollection's
> init() method). I then built a SizedCacheFactory that builds
> a SizedCacheCollection, decorates it with a
> GenericCacheCollectionManager, builds a cache, and decorates
> it with the SizedCacheCollection I've just build.
>
> To enable a time-based cache, I subclass
> GenericCacheCollectionManager with
> TimedCacheCollectionManager that's told about a cache item's
> lifespan in its init() method. The factory then assembles
> these like the GenericCacheFactory, decorating the collection
> with the TimedCache manager instead of the GenericCache manager.
>
> Does anyone have any advice/critique/etc. on doing things like this?
> Is this a "proper" implementation of using the decorator pattern?
>
> The end result, regardless, is pretty cool...I just create
> the concrete factory for the type of cache I need, call its
> createCache method, and it gives me the correct, decorated
> GenericCache.
>
> -Joe
>
>
>
>
> --
> For Tabs, Trees, and more, use the jComponents:
> http://clearsoftware.net/client/jComponents.cfm
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported by
> Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at
> www.mail-archive.com/[email protected]
>
