9.2. Borg¶

• EN: Borg

• PL: Borg

• Type: object

9.2.2. Implementation¶

class Borg:
__shared_state: dict = {}

def __init__(self):
self.__dict__ = self.__shared_state


9.2.3. Borg vs Singleton¶

• Source 1

The real reason that borg is different comes down to subclassing.

If you subclass a borg, the subclass' objects have the same state as their parents classes objects, unless you explicitly override the shared state in that subclass. Each subclass of the singleton pattern has its own state and therefore will produce different objects.

Also in the singleton pattern the objects are actually the same, not just the state (even though the state is the only thing that really matters).

9.2.4. References¶

1

https://stackoverflow.com/a/1318444