hup.base.abc module

Metaclasses and Abstract Base Classes for frequently used design patterns.

class Isolated

Bases: object

Abstract Base Class for per-instance isolated classes.

The Isolated base class is a helper class, which is included to allow instance checking against the IsolatedMeta metaclass.

class IsolatedMeta

Bases: abc.ABCMeta

Metaclass for isolated classes.

Isolated classes create a new subclass for any instance to allow the modification of class methods without side effects. Common use cases for isolated classes include Singletons, Multitons and built classes, that avoid generic programming in favor of higher efficiency or lower memory usage.

class Multiton

Bases: object

Abstract Base Class for Multiton Classes.

The Multiton base class is a helper class, which is included to allow instance checking against the MultitonMeta metaclass.

class MultitonMeta

Bases: hup.base.abc.IsolatedMeta

Metaclass for Multitons.

Multiton Classes only create a single instance per given arguments by using a new subclass for class isolation. This allows a controlled creation of multiple distinct objects, that are globally accessible and unique. Multiton classes may be regarded as a generalization of Singletons in the sense of ‘Collections of Singletons’. Common use cases comprise application global configurations, caching and collections of constants (given as immutable objects).

class Proxy

Bases: abc.ABC

Abstract Base Class for Connect Proxies.

connect(*args, **kwds) → None

Establish connection to source.

disconnect() → None

Close connection to source.

pull() → None

Pull state changes from source.

push() → None

Push state changes to source.

class Singleton

Bases: object

Abstract Base Class for Singletons.

The Singleton base class is a helper class, which is included to allow instance checking against the SingletonMeta metaclass.

class SingletonMeta

Bases: hup.base.abc.IsolatedMeta

Metaclass for Singletons.

Singleton classes only create a single instance per application and therefore by definition are special case of isolated classes. This creation pattern ensures the application global uniqueness and accessibility of instances, comparably to global variables. Common use cases comprise logging, sentinel objects and application global constants (given as immutable objects).

sentinel(cls: hup.base.abc.SingletonMeta) → object

Class decorator that creates a Sentinel from a Singleton class.

Parameters:cls – Subclass of the class Singleton
Returns:Instance of the given Singleton class, which adopts a class like behaviour, including the ability of instantion, hashing and its representation.