Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use of __new__ solution in Clear category for Capital City by kkkkk
class Capital:
"""Singleton for the capital city for a country."""
class __Capital:
"""Implementation of the Singleton class."""
def __init__(self, city_name):
self.city_name = city_name
def name(self):
"""Return name of capital's city."""
return self.city_name
# The singleton instance.
_instance = None
def __new__(cls, city_name):
"""Ensures only one instance of implementation is created."""
if not Capital._instance:
Capital._instance = Capital.__Capital(city_name)
return Capital._instance
March 22, 2020
Comments: