feat: 建造模式

This commit is contained in:
裴浩宇 2023-10-27 18:28:33 +08:00
parent 208bc840bb
commit 2e9eff0ead
3 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package com.pnkx.designpatterns.builder;
/**
* BYDBuilder
*
* @author 裴浩宇
* @version 1.0
* @date 2023/10/27 15:15
* @description BYD汽车建造
*/
public class BYDBuilder {
}

View File

@ -0,0 +1,38 @@
package com.pnkx.designpatterns.builder;
/**
* Builder
*
* @author 裴浩宇
* @version 1.0
* @date 2023/10/27 14:23
* @description 建造者
*/
public abstract class Builder {
//
protected Car car = new Car();
/**
* 建造发动机
*/
public abstract void buildEngine();
/**
* 建造轮胎
*/
public abstract void buildTire();
/**
* 建造座位
*/
public abstract void buildSeat();
/**
* 获取车
* @return
*/
public Car getCar() {
return car;
}
}

View File

@ -0,0 +1,43 @@
package com.pnkx.designpatterns.builder;
/**
* Car
*
* @author 裴浩宇
* @version 1.0
* @date 2023/10/27 14:20
* @description 产品类
*/
public class Car {
// 发动机
private String engine;
// 轮胎
private String tire;
// 座位
private String seat;
public String getEngine() {
return engine;
}
public void setEngine(String engine) {
this.engine = engine;
}
public String getTire() {
return tire;
}
public void setTire(String tire) {
this.tire = tire;
}
public String getSeat() {
return seat;
}
public void setSeat(String seat) {
this.seat = seat;
}
}