Python的设计模式

1.单例模式

class Dog(object):

    __instance = None
  def __new__(cls):
    if cls.__instance == None:
      cls.__instance = object.__new__(cls)
      return cls.__instance
    else:
      return cls.__instance

 

posted @ 2017-10-11 19:38  我为Xin媛学Python  阅读(123)  评论(0)    收藏  举报