Singleton Pattern
Definition-ensures a class has only one instance, and provide a global point of access it.
Problem:
There are many objects we only need one of: thread pools, caches, dialog boxes, objects that handle preferences and registry settings, objects used for logging, and objects that act as device drivers to devices like printers and graphics cards. In fact, for many of these types of objects, if we were to instantiate more than one we’d run into all sorts of problems like incorrect program behavior, overuse of resource, or inconsistent results.
Advantage:
With the singleton pattern, we can create our objects only when they are needed.
Key Points:
Be careful for multithread












































//if u find sth interesting, pls contact me. QQ:95491590