TWIG::2020.07.20

Today lolol·2020년 7월 20일
0

TWIG

목록 보기
11/17

- Singleton

how to implement singleton in python?
there is really lot of way to do. even there is a library.
(even if this library's last update is 3 years ago...)

this moment i do not fully understand those codes.
but i need to implement code. so i choose some alternative.

...
    _instance = None

    @classmethod
    def _getInstance(cls):
        return cls._instance

    @classmethod
    def instance(cls, *args, **kargs):
        cls._instance = cls(*args, **kargs)
        cls.instance = cls._getInstance

        return cls._instance
...

this code has critical cons that is can not use constructor. so i just call __init__like method once.

    @classmethod
    def init_like(cls):
        # initialize instance
        pass

i know this is bad. and quite ugly ☹️
so i refactor this part later.

- Guide

- Oh my AWS

profile
working making doing makes us 🤖

0개의 댓글