Python版 https://github.com/faif/python-patterns/blob/master/creational/borg.py #!/usr/bin/env python # -*- coding: utf-8 -*- """ *What is this pattern about? The Borg pattern (also known as the Monostate pattern) is a way to implement singl…
Python版 https://github.com/faif/python-patterns/blob/master/creational/factory_method.py #!/usr/bin/env python # -*- coding: utf-8 -*- """*What is this pattern about? >>这个设计模式是干什么的 The Factory Method pattern can be used to create an i…
Python版 https://github.com/faif/python-patterns/blob/master/creational/pool.py #!/usr/bin/env python # -*- coding: utf-8 -*- """ *What is this pattern about? This pattern is used when creating an object is costly (and they are created frequ…
Python版 https://github.com/faif/python-patterns/blob/master/creational/abstract_factory.py #!/usr/bin/env python # -*- coding: utf-8 -*- """ *What is this pattern about? In Java and other languages, the Abstract Factory Pattern serves to pr…
Python版 https://github.com/faif/python-patterns/blob/master/creational/builder.py #!/usr/bin/python # -*- coding : utf-8 -*- """ *What is this pattern about? It decouples the creation of a complex object and its representation, so that the…
Python版 https://github.com/faif/python-patterns/blob/master/creational/prototype.py #!/usr/bin/env python # -*- coding: utf-8 -*- """ *TL;DR80 Creates new object instances by cloning prototype. """ class Prototype(object): va…
Python版 https://github.com/faif/python-patterns/blob/master/creational/lazy_evaluation.py #!/usr/bin/env python # -*- coding: utf-8 -*- """ Lazily-evaluated property pattern in Python. https://en.wikipedia.org/wiki/Lazy_evaluation *Referenc…
//饿汉式:资源利用率较低(无论是否需要都会创建),性能较高(使用前无需判断实例是否存在,可直接使用) public class EagerSingleton{ private static final EagerSingleton instance=new EagerSingleton(); private EagerSingleton(){} public static EagerSingleton getInstance(){ return instance; } } //懒汉式:资源利用…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAW0AAABvCAIAAACo3AbKAAALvUlEQVR4nO1dUa7cOA7U/c+zwJxkf4…
package com.tn.pattern; public class Client { public static void main(String[] args) { Director director=Director.getInstance(); director.construct(new ConcreteBuilder1()); director.construct(new ConcreteBuilder2()); } } class Director{ static Direct…