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/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/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/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…
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…
public class Test { public static void main(String[] args){ try{ Factory.factory("A").doSth(); Factory.factory("B").doSth(); Factory.factory("C").doSth(); }catch(BadProductException e){ e.printStackTrace(); } } } class Factor…
一.简单工厂模式 简单工厂模式Simple Factory,又称静态工厂方法模式.它是类的创建模式.是由一个工厂对象决定创建出哪一种产品类的实例,是不同的工厂方法模式的一个特殊实现. 优点: u 模式的核心是工厂类,该类中含有必要的判断逻辑,可以决定在什么时候创建哪一个产品类的实例,客户端可以免除直接创建产品对象的责任,而仅仅负责“消费”产品. u 简单工厂模式实现了对责任的分割. 缺点: u 当产品类有复杂的多层次等级结构时,工厂类只有它自己.以不变应万变. u 模式中工厂类集中了所有的产品创…