diff --git a/src/main/java/com/msb/builder/ComplexTerrainBuilder.java b/src/main/java/com/msb/builder/ComplexTerrainBuilder.java new file mode 100644 index 0000000..93e5bf8 --- /dev/null +++ b/src/main/java/com/msb/builder/ComplexTerrainBuilder.java @@ -0,0 +1,44 @@ +package com.msb.builder;/** + * @Author bingor + * @Date 2022/10/18 16:34 + * @Description: com.msb.builder + * @Version: 1.0 + */ + +/** + *@ClassName ComplexTerrainBuilder + *@Description TODO + *@Author bingor + *@Date 2022/10/18 16:34 + *@Version 3.0 + */ +public class ComplexTerrainBuilder implements TerrainBuilder { + + private Terrain terrain = new Terrain(); + + @Override + public TerrainBuilder buildWall() { + Wall wall = new Wall(10, 10, 50, 50); + terrain.setWall(wall); + return this; + } + + @Override + public TerrainBuilder buildFort() { + Fort fort = new Fort(10, 10, 50, 50); + terrain.setFort(fort); + return this; + } + + @Override + public TerrainBuilder buildMine() { + Mine mine = new Mine(10, 10, 50, 50); + terrain.setMine(mine); + return this; + } + + @Override + public Terrain build() { + return terrain; + } +} diff --git a/src/main/java/com/msb/builder/Main.java b/src/main/java/com/msb/builder/Main.java new file mode 100644 index 0000000..8bace65 --- /dev/null +++ b/src/main/java/com/msb/builder/Main.java @@ -0,0 +1,26 @@ +package com.msb.builder;/** + * @Author bingor + * @Date 2022/10/18 16:42 + * @Description: com.msb.builder + * @Version: 1.0 + */ + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/18 16:42 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + 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号") + .build(); + } +} diff --git a/src/main/java/com/msb/builder/Person.java b/src/main/java/com/msb/builder/Person.java new file mode 100644 index 0000000..72167f3 --- /dev/null +++ b/src/main/java/com/msb/builder/Person.java @@ -0,0 +1,59 @@ +package com.msb.builder;/** + * @Author bingor + * @Date 2022/10/18 16:51 + * @Description: com.msb.builder + * @Version: 1.0 + */ + +/** + *@ClassName Person + *@Description TODO + *@Author bingor + *@Date 2022/10/18 16:51 + *@Version 3.0 + */ +public class Person { + private int id; + private int age; + private String name; + private int score; + private Location location; + + public static class PersonBuilder { + Person person = new Person(); + public PersonBuilder buildBasicInfo(int id, String name) { + person.id = id; + person.name = name; + return this; + } + + public PersonBuilder buildAge(int age) { + person.age = age; + return this; + } + + public PersonBuilder buildScore(int score) { + person.score = score; + return this; + } + + public PersonBuilder buildLocation(String street, String roomNo) { + person.location = new Location(street, roomNo); + return this; + } + + public Person build() { + return person; + } + } +} + +class Location { + private String street; + private String roomNo; + + public Location(String street, String roomNo) { + this.street = street; + this.roomNo = roomNo; + } +} \ No newline at end of file diff --git a/src/main/java/com/msb/builder/Terrain.java b/src/main/java/com/msb/builder/Terrain.java new file mode 100644 index 0000000..d0e33b1 --- /dev/null +++ b/src/main/java/com/msb/builder/Terrain.java @@ -0,0 +1,61 @@ +package com.msb.builder;/** + * @Author bingor + * @Date 2022/10/18 15:46 + * @Description: com.msb.builder + * @Version: 1.0 + */ + +/** + *@ClassName Terrain + *@Description TODO + *@Author bingor + *@Date 2022/10/18 15:46 + *@Version 3.0 + */ +public class Terrain { + private Wall wall; + private Fort fort; + private Mine mine; + + public void setWall(Wall wall) { + this.wall = wall; + } + + public void setFort(Fort fort) { + this.fort = fort; + } + + public void setMine(Mine mine) { + this.mine = mine; + } +} + +class Wall { + private int x, y, width, height; + public Wall(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } +} + +class Fort { + private int x, y, width, height; + public Fort(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } +} + +class Mine { + private int x, y, width, height; + public Mine(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } +} diff --git a/src/main/java/com/msb/builder/TerrainBuilder.java b/src/main/java/com/msb/builder/TerrainBuilder.java new file mode 100644 index 0000000..9fe2fe8 --- /dev/null +++ b/src/main/java/com/msb/builder/TerrainBuilder.java @@ -0,0 +1,14 @@ +package com.msb.builder; + +/** + * @Author bingor + * @Date 2022/10/18 16:33 + * @Description: com.msb.builder + * @Version: 1.0 + */ +public interface TerrainBuilder { + public TerrainBuilder buildWall(); + public TerrainBuilder buildFort(); + public TerrainBuilder buildMine(); + public Terrain build(); +}