A Singleton class Returns the same instance no matter how many times an application requests it. The singleton design returns only the same instance at a time; A typical class permits callers to create as many instances of the class as they want, requesters can create many instances as long as they want. ; Whereas with a singleton class, there can is only one instance of the class per process. A singleton object provides a global point of access to the resources of its class. Singletons was used in situations where this single point of control was desirable, such as with classes the offer some GE Neral Service or resource.
You obtain the global instance from a singleton class through a factory method. The class lazily creates its sole instance the first time it's requested and thereafter ensures that's no other instance CA n be created. A Singleton class also prevents callers from copying, retaining, or releasing the instance. The Singleton class does not allow the user to make modifications to the copy and so on; You might create your own singleton classes if you find the need for them. You can do it yourself by creating a singleton class that you think is necessary; for example If you had a class that provides sounds to other objects in an application, you might make it a singleton.
Several Cocoa Framework classes is singletons. They include Nsfilemanager, Nsworkspace, and, in UIKit, UIApplication and Uiaccelerometer. The name of the factory method returning the singleton instance have, by convention, the form Sharedclasstype. Examples from the Cocoa frameworks is Sharedfilemanager, Sharedcolorpanel, and SharedWorkspace.
A single example design pattern is gradually explained