Skip to main content

My implementation of Singleton Design Pattern based on metaclass method.

Project description

Pattern Singleton

Python PyPi License Build Coverage

Description

My implementation of Singleton Design Pattern based on metaclass method.

Installation

Just use (No other package is needed):

$ pip install patternSingleton

Example Usage

from patternSingleton import Singleton


class Example(metaclass=Singleton):
    def __init__(self):
        self.variable = 1


if __name__ == '__main__':
    example_01 = Example()
    example_02 = Example()

    print(example_01.variable)  # displays 1
    print(example_02.variable)  # displays 1

    example_01.variable = 2     # changes value for every instance of Example class

    print(example_01.variable)  # displays 2
    print(example_02.variable)  # displays 2

Credits

This package was created by Marcin Mysliwiec with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2020-10-20)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pattern_singleton-1.0.0.tar.gz (10.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page