I know this pattern is used in order to create multiple instances with the same state, but i really don't understand how it works.
class Borg:
_shared_state = {}
def __init__(self):
self.__dict__ = self._shared_state
class Singleton(Borg):
def __init__(self, **kwargs):
Borg.__init__(self)
self._shared_state.update(kwargs)
def __str__(self):
return str(self._shared_state)
More specifically, what happens when in the Singleton init method I call Borg.init ?
Aucun commentaire:
Enregistrer un commentaire