Uživatelské nástroje

Nástroje pro tento web


navody:python_design_pattern

Návrhové vzory - Python

Singleton

class Singleton(type):
    _instances = {}
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]
 
class Setup(metaclass=Singleton):
    pass
navody/python_design_pattern.txt · Poslední úprava: 2014/04/09 10:14 autor: jules