I'm not picking any sides, The Idea of a getInstance method (Singleton), as you guys have been saying, is to have a static way to get a non-static instance of a class. Also, that way of working makes it easier for the creator of that class to know his class will only get instantiated once.
There are other advantages like the presence of a constructor and probably many other things that you guys have also mentioned. All this to say absolutely nothing:) -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of JesterXL Sent: October 29, 2005 12:14 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Newbie AS3 question That makes perfect sense and is a good reason. So, from this 2nd conversation, I've gleaned something else to add to the list: - getInstance() is a unspoken standard that implies the class is a Singleton used in other languages other than ActionScript - getInstance() treats a class as a true class without static properties, thus making it easier to go from Singleton to a true class without having to change a bunch of code, because all it really does is make 1, and only 1, instance of itself. The thought of changing multiple lines of code to go from static to non would really suck; that drives the point home for me. Thanks for taking the time to explain it Spike! ----- Original Message ----- From: "Spike" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com> Sent: Saturday, October 29, 2005 12:05 PM Subject: Re: [Flashcoders] Newbie AS3 question It's not necessarily any better from an implementation point of view. You can often do the same thing with a static class as you can with a singleton. The big benefit comes if you need to change from singleton/static to different instances for each invocation. If you have followed the static class approach you have static method calls all through your code that you will need to change if the class now needs to be non-static. If you have followed the singleton approach, you only need to change the line of code that retrieves the instance inside the singleton. That's a pretty big benefit IMO. To get back to where we started all this, the original statement that brought all this up was your suggestion that Foo.someMethod() was identical to Foo.getInstance().someMethod() Whether one is better than another is something that can be debated to death, and often is on Java mailing lists, but hopefully you'll at least agree that they are indeed doing different things. Spike On 10/29/05, JesterXL <[EMAIL PROTECTED]> wrote: > > I would have 20 static classes, not 20 if/then/switch statements. You'd > have that same if/then statement in the getInstance() function, though, to > know which formatter to return. > > Again, I'm having a hard time seeing why getInstance is more appopriate > than > just making static classes, and how this applys to the Singleton pattern. > > > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders