On 9/13/07, Alan Watts <[EMAIL PROTECTED]> wrote: > hi all, > > I have a model class that contains xml data for a file I am > manipulating. What would be the difference between setting it up as > a singleton and just accessing it via static vars and methods?
I wouldn't use either of those solutions, because that locks you in to only ever having 0 (static) or 1 (singleton) instances of said class. Should your architecture change in the future, you'd have to make some serious revisions. I generally (but not always!) find its better to keep such things as a standard class and use various strategies (searching through display ancestry, passing as arguments to constructor, setting as properties, using global "dictionaries", etc.) to connect the instances to other object instances that use them. > new myFile(); > myFile.getInstance().setFilename()... etc. That's not quite the Singleton pattern. In the Singleton pattern, you don't need to explicitly instantiate your class outside of the class's code -- it would effectively do nothing. The Singleton pattern would be more like: // CLASS CODE import flash.errors.IllegalOperationError; class MyFile { function MyFile() { super(); if (_instance is MyFile) { throw new IllegalOperationError(); } } public static function get instance():MyFile { if (!(_instance is MyFile)) { _instance = new MyFile(); } return _instance; } public function myMethod():void { trace("myMethod() was called"); } private static var _instance:MyFile = null; } // OTHER CODE MyFile.instance.myMethod(); -- T. Michael Keesey Director of Technology Exopolis, Inc. 2894 Rowena Avenue Ste. B Los Angeles, California 90039 http://exopolis.com/ -- http://tmkeesey.net/ _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com