+ 1
Singleton class
As i have created a example of singleton. Wanna ask if it is correct ? class Singleton: __instance=None def __init__(self): if Singleton.__instance!=None: raise Exception("This class is Singleton") else: Singleton.__instance=self obj=Singleton() #instance created obj1=Singleton() #exception error "This class is Singleton"
2 ответов
+ 1
I think it works. And depending on requirement, we can return the instance instead of raising an exception.
0
thanx buddy