8.2. Borg

  • EN: Borg

  • PL: Borg

  • Type: object

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). [1]

8.2.1. Pattern

design-patterns/creational/img/designpatterns-borg-pattern.png

8.2.2. Problem

design-patterns/creational/img/designpatterns-borg-problem.png


8.2.3. Solution

design-patterns/creational/img/designpatterns-borg-solution.png

class Borg:
    shared_state: dict = {}

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

8.2.4. References