Aaron Ross wrote:
Hi Eric,

class. What I'd like is to have my model (as in MVC) objects reuse the process or maybe even server shared objects without doing any of these:

1. Using a singleton utility class
2. Needing to pass objects to model objects' new() in teh controllers
3. Instantiating the objects in the model classes themselves

I'm not sure if this violates 3 (the models classes have to know what resources they need, so i am not sure what wouldn't), but could you use a singleton for the resource and a factory to access it? The model classes call a "static" factory method that handles the configuration, cache, etc...

This is what I'm thinking I'll do. It seems to be the most "natural" in this case. I was reading this paper by Andy Wardly http://www.template-toolkit.org/tpc5/camelot/index.html which has a collection of resource classes that seem to act in a similar method at some level (providing a resource with a class that could be implemented as a singleton).


This solves the problem of having configuration and resource allocation
code in your model objects. It does mean that you have to write factory
classes for your resources, but they ought to be quite simple.

Writing factory methods compared to littering code with instantiation of objects all objects are going to need lends itself to an easy and obvious first choice. ...For me, at least. ;)


I've done a fair amount of Objective-C (Mac OS X Cocoa and Openstep) and there's a number of classes that work in a similar fashion - simple, clean, and functional. The reason I like it is because I don't need to worry about passing stuff around - just get a static instance and go to town. (For those interested or in the know, I'm talking about NSNotificationCenter, NSFileManager, and other similar classes).

Thanks for the input!

--
Eric Sammer
[EMAIL PROTECTED]
http://www.ineoconcepts.com



Reply via email to