标签:
classProduct {
private String partA;//定义部件,部件可以是任意类型,包括值类型和引用类型
private String partB;
private String partC;
}
abstract classBuilder{
//创建产品对象
protected Product product=newProduct();
public abstract void buildPartA();
public abstract void buildPartB();
public abstract void buildPartC();
//返回产品对象
public Product getResult(){
return product;
}
}
classDirector{
private Builder builder;
public Director(Builder builder){
this.builder=builder;
}
//管理控制产品构建与组装方法
publicProduct construct(){
builder.buildPartA();
builder.buildPartB();
builder.buildPartC();
return builder.getResult();
}
}
……
Builder builder =newConcreteBuilder();//可以通过配置文件来存储具体建造者类ConcreteBuilder的类名,使得更换新的建造者时无须修改源代码,系统扩展更为方便
Director director =new Director(builder);
Product product = director.construct();
……
protectedvoid dialog(){
AlertDialog.Builder builder =newBuilder(Main.this);
builder.setMessage("确认退出吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认",newOnClickListener(){
@Override
publicvoid onClick(DialogInterface dialog,int which){
dialog.dismiss();
Main.this.finish();
}
});
builder.setNegativeButton("取消",newOnClickListener(){
@Override
publicvoid onClick(DialogInterface dialog,int which){
dialog.dismiss();
}
});
builder.create().show();
}
标签:
原文地址:http://www.cnblogs.com/Doing-what-I-love/p/5621188.html