Chapter 17. The Singleton Design Pattern

 <  Day Day Up  >  

[The Singleton pattern's purpose is to] ensure a class has only one instance, and provide a global point of access to it.

”from Design Patterns: Elements of Reusable Object-Oriented Software (the so-called GoF book discussed in Chapter 15)

Sometimes an application needs only a single instance of a particular class and should not create more than that one instance. For example, an order form might need one FormProcessor . A game might need one LevelManager . A text editor might need one GUIBuilder . Or a chat might need one SocketManager . In each of those applications, creating more than one instance of the FormProcessor , LevelManager , GUIBuilder , or SocketManager classes could cause problems. For example, having multiple SocketManager s might lead to multiple open socket connections, which would waste resources and potentially disrupt communications. To prevent an application from creating more than one instance of a class and to give various parts of the application access to that one instance we use the Singleton pattern.

 <  Day Day Up  >  


Essential ActionScript 2.0
Essential ActionScript 2.0
ISBN: 0596006527
EAN: 2147483647
Year: 2004
Pages: 177
Authors: Colin Moock

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net