建造模式Builder

建造模式Builder

 

/**
 * 抽象建造者
 */
public abstract class Builder {
	
	public abstract void buildPart1();
	
	public abstract void buildPart2();
	
	public abstract Product retrieveResult();

}

 

 
/**
 * 具体建造着
 */
public class ConcreteBuilder extends Builder {
	
	private Product product = new Product();

	@Override
	public void buildPart1() {

	}

	@Override
	public void buildPart2() {

	}

	@Override
	public Product retrieveResult() {
		return product;
	}

}
 
/**
 * 产品
 */
public class Product {

}
 
/**
 * 导演着
 */
public class Director {
	
	private Builder builder;
	
	public void construct() {
		builder = new ConcreteBuilder();
		builder.buildPart1();
		builder.buildPart2();
		builder.retrieveResult();
	}

}
 
public class TestBuilder {
	
	public static void main(String[] args) {
		ConcreteBuilder concreteBuiler = new ConcreteBuilder();
		Director director = new Director();
		director.construct();
		Product product = concreteBuiler.retrieveResult();
	}

}
 

posted on 2016-06-03 08:25  三少爷的剑123  阅读(111)  评论(0编辑  收藏  举报

导航