用Python的类变量实现单一模式

类变量紧接在类名后面定义,相当于java和c++的static变量

实例变量在__init__里定义,相当于java和c++的普通变量

class DaoCassandra():

    __pool = None
    __maps = {}
    __cfs = {}

    @classmethod
    def getColumnFamilyMap(cls,cf):
        """
        get ColumnFamilyMap according to columnFamily name
        """
        if(cf in cls.__maps):
            return cls.__maps[cf]
        if(cls.__pool is None):
            cls.__pool = ConnectionPool(keyspace=cls.keyspace, server_list=cls.server_list,timeout=cls.timeout)
        col_fam = ColumnFamily(cls.__pool, cf)
        map = ColumnFamilyMap(Msg, col_fam)
        cls.__maps[cf] = map
        return map

你可能感兴趣的:(python)