< Day Day Up > |
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 > |