so why discuss it at allsingleton is one of the most famous of all design patterns it is useful in overly object-oriented languagesand is vital part of traditional objectoriented programming more relevantlythe idea behind singleton is usefuleven if we implement that idea in totally different way in python the basic idea behind the singleton pattern is to allow exactly one instance of certain object to exist typicallythis object is sort of manager class like those we discussed in when to use object-oriented programming such objects often need to be referenced by wide variety of other objectsand passing references to the manager object around to the methods and constructors that need them can make code hard to read insteadwhen singleton is usedthe separate objects request the single instance of the manager object from the classso reference to it need not to be passed around the uml diagram doesn' fully describe itbut here it is for completenesssingleton +instancestatic +get_instance()static in most programming environmentssingletons are enforced by making the constructor private (so no one can create additional instances of it)and then providing static method to retrieve the single instance this method creates new instance the first time it is calledand then returns that same instance each time it is called again singleton implementation python doesn' have private constructorsbut for this purposeit has something even better we can use the __new__ class method to ensure that only one instance is ever createdclass oneonly_singleton none def __new__(cls*args**kwargs)if not cls _singletoncls _singleton super(oneonlycls __new__(cls*args**kwargsreturn cls _singleton