标签:end 多个 tengine 代码 http this turn engine getch
这次来看下生成器模式,先来看下类图:
那么来说下特点吧:
来看下代码吧:
public abstract class AbstractCarBuilder { public Car car = new Car(); public abstract AbstractCarBuilder builderName(String name); public abstract AbstractCarBuilder builderTire(String Tire); public abstract AbstractCarBuilder builderEngine(String Engine); public abstract AbstractCarBuilder builderChassis(String Chassis); public abstract Car getCar(); }
public class Car { private String name; private String tire; private String engine; private String chassis; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTire() { return tire; } public void setTire(String tire) { this.tire = tire; } public String getEngine() { return engine; } public void setEngine(String engine) { this.engine = engine; } public String getChassis() { return chassis; } public void setChassis(String chassis) { this.chassis = chassis; } @Override public String toString() { String car = name + "," + tire + "," + engine + "," + chassis; return car; } }
public class CarBuilder extends AbstractCarBuilder { @Override public AbstractCarBuilder builderName(String name) { car.setName(name); return this; } @Override public AbstractCarBuilder builderTire(String Tire) { car.setTire(Tire); return this; } @Override public AbstractCarBuilder builderEngine(String Engine) { car.setEngine(Engine); return this; } @Override public AbstractCarBuilder builderChassis(String Chassis) { car.setChassis(Chassis); return this; } @Override public Car getCar() { return car; } }
标签:end 多个 tengine 代码 http this turn engine getch
原文地址:https://www.cnblogs.com/shenqiaqia/p/11370773.html