Essential ActionScript 2.0

 <  Day Day Up  >  

Beware that the Singleton pattern can turn an object-oriented program into a series of haphazard global functions and variables , negating most of the benefits of OOP. You should use the Singleton pattern when you need to limit the number of instances created by a class, not just when you want to access something globally. If you are tempted to use a Singleton simply as a repository for global variables, you should stop, rethink the problem, and try to fit the services you're implementing into some logically encapsulated structure with the rest of your program. When code is spread loosely around in global variables and functions, it's much harder to maintain, extend, and understand than when it's neatly packed into self-contained units. For further reading on this topic, see:

Global Variables Are Bad , from the Portland Pattern Repository's Wiki

http://c2.com/cgi/wiki?GlobalVariablesAreBad

Use Your Singletons Wisely , by J. B. Rainsberger

http://www-106.ibm.com/developerworks/ webservices /library/co-single.html

 <  Day Day Up  >  

Категории