坦克大战(一期)-设计模式版-Builder模式1.1

DesignPatterns
bingor_yhj 2 years ago
parent 2a3c1c5a3c
commit a568aa8241

@ -17,10 +17,10 @@ public class Main {
TerrainBuilder terrainBuilder = new ComplexTerrainBuilder();
Terrain terrain = terrainBuilder.buildWall().buildFort().buildMine().build();
Person person = new Person.PersonBuilder().buildBasicInfo(1, "bingor")
.buildAge(33)
.buildScore(100)
.buildLocation("机场路", "8号")
Person person = new Person.PersonBuilder().basicInfo(1, "bingor")
.age(33)
.score(100)
.location("机场路", "8号")
.build();
}
}

@ -21,23 +21,23 @@ public class Person {
public static class PersonBuilder {
Person person = new Person();
public PersonBuilder buildBasicInfo(int id, String name) {
public PersonBuilder basicInfo(int id, String name) {
person.id = id;
person.name = name;
return this;
}
public PersonBuilder buildAge(int age) {
public PersonBuilder age(int age) {
person.age = age;
return this;
}
public PersonBuilder buildScore(int score) {
public PersonBuilder score(int score) {
person.score = score;
return this;
}
public PersonBuilder buildLocation(String street, String roomNo) {
public PersonBuilder location(String street, String roomNo) {
person.location = new Location(street, roomNo);
return this;
}

Loading…
Cancel
Save