#!/bin/python3

class Singleton():

	__single = None
	__right_way = False

	def __init__(self, name):
		print("Comes to init")
		if not Singleton.__right_way:
			print("Comes to err")
			raise RuntimeError("CREATE USING RIGHT WAY")

		if not Singleton.__single:
			self.x = name

	@classmethod
	def getInstance(cls, name):
		if not cls.__single:
			cls.__right_way = True
			cls.__single = Singleton(name)
		return cls.__single

	def __str__(self):
		return str(self.x)

def main():

	print ("Singleton Demo: Singleton always the returns the same object once object is created.")

	i1 = Singleton.getInstance("RightWay")
	#i1 = Singleton("WrongWay")
	print(i1)
	i2 = Singleton.getInstance("RightWay2")
	print(i2)

if __name__=="__main__":main()
