
设计模式
hsc_1
这个作者很懒,什么都没留下…
展开
-
常用的设计模式
策略模式它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变换,不会影响到客户的使用。(各个算法实现一个接口)代理模式:为其他对象提供一种代理以控制对这个对象的访问。单例模式:保证一个类只有一个实例,并提供一个访问他的全局访问点。适配器:将一个类的接口,转化为客户希望的另一个接口interface ChinaPower{ public void twoStep();}c...原创 2018-03-20 21:16:23 · 125 阅读 · 0 评论 -
python实现单例模式总结
装饰器def singleton(cls): def get_instance(*args, **kwargs): if not hasattr(cls, "_instance"): cls._instance = cls(*args, **kwargs) return cls._instance return get_i...原创 2018-07-30 17:29:47 · 1236 阅读 · 0 评论 -
python中元类的使用
def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" # This requires a bit of explanation: the basic idea is to make a dummy # metaclass for one level of class in...原创 2018-08-06 21:57:32 · 391 阅读 · 0 评论