标签:c class code a ext int
public interface Builder {
public void buildHead();
public void buildBody();
public void buildHand();
public void buildFoot();
public Person buildPerson();
}
public class ManBuilder implements Builder{
Person person;
public ManBuilder(){
person = new Man();
}
@Override
public void buildHead() {
person.setHead("build man‘s
head!");
}
@Override
public void buildBody() {
person.setBody("build man‘s
body!");
}
@Override
public void buildHand() {
person.setHand("build man‘s
hand!");
}
@Override
public void buildFoot() {
person.setFoot("build man‘s
food!");
}
@Override
public Person buildPerson() {
return person;
}
}
public class Person {
private String head;
private String hand;
private String body;
private String foot;
public String getHead() {
return head;
}
public void setHead(String head) {
this.head = head;
}
public String getHand() {
return hand;
}
public void setHand(String hand) {
this.hand = hand;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getFoot() {
return foot;
}
public void setFoot(String foot) {
this.foot = foot;
}
}
public class PersonDirector {
//指挥创建
public Person ConstructPerson(Builder b)
{
b.buildFoot();
b.buildHand();
b.buildHead();
b.buildBody();
return b.buildPerson();
}
}
public class Man extends Person{
}
public class BuilderDemo {
/**
* @param args the command line
arguments
*/
public static void main(String[] args) {
// TODO code application logic here
PersonDirector pd = new
PersonDirector();
Person person =
pd.ConstructPerson(new ManBuilder());
System.out.println(person.getHead());
System.out.println(person.getBody());
System.out.println(person.getHand());
System.out.println(person.getFoot());
}
}
Builder(建造者模式),布布扣,bubuko.com
Builder(建造者模式)
标签:c class code a ext int
原文地址:http://www.cnblogs.com/www-zhoushuai-com/p/3754017.html