mlpy.modules.patterns.Borg

class mlpy.modules.patterns.Borg[source]

Bases: object

Class ensuring that all instances share the same state.

The borg design pattern ensures that all instances of a class share the same state and provides a global point of access to the shared state.

Rather than enforcing that only ever one instance of a class exists, the borg design pattern ensures that all instances share the same state. That means every the values of the member variables are the same for every instance of the borg class.

The member variables which are to be shared among all instances must be declared as class variables.

See also

Singleton

Notes

One side effect is that if you subclass a borg, the objects all have the same state, whereas subclass objects of a singleton have different states.

Examples

Create a borg class:

>>> from mlpy.modules.patterns import Borg
>>> class MyClass(Borg):
>>>     shared_variable = None

Note

Project: Code from ActiveState.
Code author: Alex Naanou
License: CC-Wiki