python的单例模式

python学习网 2017-11-09 18:23:02
class Solution:
    # @return: The same instance of this class every time
    __instance = None
    def __init__(self):
        pass
    @classmethod
    def getInstance(cls):
        # write your code here
        if Solution.__instance is None:
            Solution.__instance = Solution()
        return Solution.__instance

  

阅读(790) 评论(0)