Skip to content

mingderwang/Singleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Singleton Design Pattern

Global State and Singleton cause the code hard to test youtube To use DI as possible.

test

add a .replit file with the following lines

language = "python3"
run = "python -m unittest discover -v"

decorator way of doing this

def singleton(class_):
    instances = {}
    def getinstance(*args, **kwargs):
        if class_ not in instances:
            instances[class_] = class_(*args, **kwargs)
        return instances[class_]
    return getinstance

@singleton
class MyClass(BaseClass):
    pass

*There are may other ways, refer to here in stackoverflow

try another way of implementation

https://github.com/tylerlaberge/PyPattyrn#singleton-pattern

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages