用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

小楼昨夜又东风    -  云代码空间

——

设计模式

2016-12-11|767阅||

摘要:package prj00; public class Role { private String sex; private String face; private String clothing; private String hairstyle; public void s

package prj00;




public class Role
{
private String sex;
private String face;
private String clothing;
private String hairstyle;

public void setSex(String sex){
this.sex= sex;
}
public void setFace(String face){
this.face= face;
}
public void setClothing(String clothing){
this.clothing= clothing;
}
public void setHairstyle(String hairstyle){
this.clothing= clothing;
}

public String getSex(){
return (this.sex);
}
public String getFace(){
return (this.face);
}
public String getClothing(){
return (this.clothing);
}
public String getHairstyle(){
return (this.hairstyle);
}
}
 abstract class RoleBuilder 
{
protected Role role = new Role();

public abstract void buildSex();
public abstract void buildFace();
public abstract void buildClothing();
public abstract void buildHairstyle();

public Role getRole()
{
return role;
}


}
 class SubRoleBuilderA extends RoleBuilder{



public void buildSex() {
role.setSex("男");

}



public void buildFace() {
role.setFace("蛇精脸");

}



public void buildClothing() {
role.setClothing("魔法斗篷");

}



public void builderHairstyle() {
role.setHairstyle("卷发");

}




@Override
public void buildHairstyle() {
// TODO Auto-generated method stub

}

}


class SubRoleBuilderB extends RoleBuilder{



public void buildSex() {
role.setSex("女");

}



public void buildFace() {
role.setFace("妲己脸");

}



public void buildClothing() {
role.setClothing("隐形铠甲");

}



public void builderHairstyle() {
role.setHairstyle("长发飘飘");

}




@Override
public void buildHairstyle() {
// TODO Auto-generated method stub

}

}

class Director 
{
private RoleBuilder ljq;
public  void setRoleBuilder(RoleBuilder ljq)
{
this.ljq = ljq;
}

public Role construct()
{
ljq.buildSex();
ljq.buildFace();
ljq.buildClothing();
ljq.buildHairstyle();
return ljq.getRole();

}


}


顶 0踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 小楼昨夜又东风
    • 等级: 中级程序员
    • 积分: 50
    • 代码: 0 个
    • 文章: 5 篇
    • 随想: 0 条
    • 访问: 0 次
    • 关注

    人气文章

    人气代码

      标签

      站长推荐