package Builder;
/**
* 工厂父类
* @author L-Seven
*
*/
public abstract class Builder {
public abstract void BuilderA();
public abstract void BuilderB();
public abstract void BuilderC();
}
/**
* 子类BuilderA
* @author L-Seven
*
*/
class BuilderA extends Builder{
@Override
public void BuilderA() {
System.out.println("BuilderA-a");
}
@Override
public void BuilderB() {
System.out.println("BuilderA-b");
}
@Override
public void BuilderC() {
System.out.println("BuilderA-c");
}
}
/**
* 子类BuilderB
* @author L-Seven
*
*/
class BuilderB extends Builder{
@Override
public void BuilderA() {
System.out.println("BuilderB-a");
}
@Override
public void BuilderB() {
System.out.println("BuilderB-a");
}
@Override
public void BuilderC() {
System.out.println("BuilderB-a");
}
}
/**
* 选择
* @author L-Seven
*
*/
class Director{
private Builder builder = null;
public void setBuilder(char builderName){
this.builder = BuilderFactory.chooseBuilder(builderName);
}
public void show(){
this.builder.BuilderA();
this.builder.BuilderB();
this.builder.BuilderC();
}
}
/**
* Builder工厂
* @author L-Seven
*
*/
class BuilderFactory{
public static Builder chooseBuilder(char builderName){
switch (builderName) {
case 'a':
return new BuilderA();
case 'b':
return new BuilderB();
default:
return null;
}
}
}
/**
* 测试类
* @author L-Seven
*
*/
class Buildertest{
public static void main(String[] args) {
Director d = new Director();
d.setBuilder('a');
d.show();
}
/**
* 工厂父类
* @author L-Seven
*
*/
public abstract class Builder {
public abstract void BuilderA();
public abstract void BuilderB();
public abstract void BuilderC();
}
/**
* 子类BuilderA
* @author L-Seven
*
*/
class BuilderA extends Builder{
@Override
public void BuilderA() {
System.out.println("BuilderA-a");
}
@Override
public void BuilderB() {
System.out.println("BuilderA-b");
}
@Override
public void BuilderC() {
System.out.println("BuilderA-c");
}
}
/**
* 子类BuilderB
* @author L-Seven
*
*/
class BuilderB extends Builder{
@Override
public void BuilderA() {
System.out.println("BuilderB-a");
}
@Override
public void BuilderB() {
System.out.println("BuilderB-a");
}
@Override
public void BuilderC() {
System.out.println("BuilderB-a");
}
}
/**
* 选择
* @author L-Seven
*
*/
class Director{
private Builder builder = null;
public void setBuilder(char builderName){
this.builder = BuilderFactory.chooseBuilder(builderName);
}
public void show(){
this.builder.BuilderA();
this.builder.BuilderB();
this.builder.BuilderC();
}
}
/**
* Builder工厂
* @author L-Seven
*
*/
class BuilderFactory{
public static Builder chooseBuilder(char builderName){
switch (builderName) {
case 'a':
return new BuilderA();
case 'b':
return new BuilderB();
default:
return null;
}
}
}
/**
* 测试类
* @author L-Seven
*
*/
class Buildertest{
public static void main(String[] args) {
Director d = new Director();
d.setBuilder('a');
d.show();
}
}
//图为输出结果