diff --git a/src/headfirst/designpatterns/builder/house/GingerbreadHouseBuilder.java b/src/headfirst/designpatterns/builder/house/GingerbreadHouseBuilder.java index 71c2cfac..ae39c443 100644 --- a/src/headfirst/designpatterns/builder/house/GingerbreadHouseBuilder.java +++ b/src/headfirst/designpatterns/builder/house/GingerbreadHouseBuilder.java @@ -1,12 +1,10 @@ package headfirst.designpatterns.builder.house; -import headfirst.designpatterns.builder.house.HouseBuilder.HouseType; - public class GingerbreadHouseBuilder extends HouseBuilder { int numWalls = 4; int numWindows = 4; String windowMaterial = "Sugar"; - String wallMaterial = "Gingerbread"; + String wallMaterial = "Gingerbread and icing"; String roofMaterial = "Twizzlers"; public GingerbreadHouseBuilder() { this.builderName = "Gingerbread House Builder"; @@ -15,12 +13,14 @@ public GingerbreadHouseBuilder() { public HouseBuilder addWalls() { // add exterior walls for (int i = 0; i < numWalls; i++) { + System.out.println("Adding wall made out of " + wallMaterial); house.addWall(new Wall(wallMaterial)); } return this; } public HouseBuilder addWindows() { for (int i = 0; i < numWindows; i++) { + System.out.println("Adding window made out of " + windowMaterial); house.addWindow(new Window(windowMaterial)); } return this; @@ -29,4 +29,8 @@ public HouseBuilder addRoof() { house.addRoof(new Roof(roofMaterial)); return this; } + public House build() { + System.out.println("Stick everything together with icing"); + return house; + } } \ No newline at end of file diff --git a/src/headfirst/designpatterns/builder/house/House.java b/src/headfirst/designpatterns/builder/house/House.java index 5674f231..fbd4f11b 100755 --- a/src/headfirst/designpatterns/builder/house/House.java +++ b/src/headfirst/designpatterns/builder/house/House.java @@ -17,9 +17,10 @@ public House() { public House setHouseType(HouseType houseType) { this.houseType = houseType; switch (houseType) { - case STONE: this.name = "My stone house"; - case WOOD: this.name = "My wood house"; - case GINGERBREAD: this.name = "My holiday gingerbread house"; + case WOOD: this.name = "My wood house"; break; + case CLAY: this.name = "My clay house"; break; + case GINGERBREAD: this.name = "My holiday gingerbread house"; break; + case STONE: this.name = "My stone house"; break; } return this; } diff --git a/src/headfirst/designpatterns/builder/house/HouseBuilder.java b/src/headfirst/designpatterns/builder/house/HouseBuilder.java index 6627489b..023ec192 100644 --- a/src/headfirst/designpatterns/builder/house/HouseBuilder.java +++ b/src/headfirst/designpatterns/builder/house/HouseBuilder.java @@ -6,7 +6,7 @@ public abstract class HouseBuilder { String builderName; enum HouseType { - STONE, WOOD, GINGERBREAD + WOOD, CLAY, GINGERBREAD, STONE } HouseType houseType; House house = new House(); diff --git a/src/headfirst/designpatterns/builder/house/HouseDirector.java b/src/headfirst/designpatterns/builder/house/HouseDirector.java index f6ce8835..e73377e7 100755 --- a/src/headfirst/designpatterns/builder/house/HouseDirector.java +++ b/src/headfirst/designpatterns/builder/house/HouseDirector.java @@ -18,9 +18,9 @@ public static void main(String[] args) { House woodHouse = woodHouseBuilder.addWalls().addWindows().addRoof().build(); System.out.println(woodHouse); - HouseBuilder stoneHouseBuilder = new StoneHouseBuilder(); - House stoneHouse = stoneHouseBuilder.addWalls().addWindows().addRoof().build(); - System.out.println(stoneHouse); + HouseBuilder clayHouseBuilder = new ClayHouseBuilder(); + House clayHouse = clayHouseBuilder.addWalls().addWindows().addRoof().build(); + System.out.println(clayHouse); HouseBuilder gingerbreadHouseBuilder = new GingerbreadHouseBuilder(); House gingerbreadHouse = gingerbreadHouseBuilder.addWalls().addWindows().addRoof().build(); diff --git a/src/headfirst/designpatterns/builder/house/StoneHouseBuilder.java b/src/headfirst/designpatterns/builder/house/StoneHouseBuilder.java index 30777364..07377af5 100644 --- a/src/headfirst/designpatterns/builder/house/StoneHouseBuilder.java +++ b/src/headfirst/designpatterns/builder/house/StoneHouseBuilder.java @@ -30,4 +30,8 @@ public HouseBuilder addRoof() { house.addRoof(new Roof(roofMaterial)); return this; } + public House build() { + System.out.println("Stick everything together with mortar"); + return house; + } } \ No newline at end of file diff --git a/src/headfirst/designpatterns/builder/house/WoodHouseBuilder.java b/src/headfirst/designpatterns/builder/house/WoodHouseBuilder.java index 087510a7..ff04c253 100644 --- a/src/headfirst/designpatterns/builder/house/WoodHouseBuilder.java +++ b/src/headfirst/designpatterns/builder/house/WoodHouseBuilder.java @@ -16,16 +16,19 @@ public WoodHouseBuilder() { public HouseBuilder addWalls() { // add exterior walls for (int i = 0; i < 4; i++) { + System.out.println("Nailing wood for wall made out of " + wallMaterial); house.addWall(new Wall(wallMaterial)); } // add interior walls for (int i = 0; i < numWalls - 4; i++) { + System.out.println("Nailing wood for interior wall made out of " + interiorWallMaterial); house.addWall(new InteriorWall(interiorWallMaterial)); } return this; } public HouseBuilder addWindows() { for (int i = 0; i < numWindows; i++) { + System.out.println("Adding window made out of " + windowMaterial); house.addWindow(new Window(windowMaterial)); } return this; @@ -34,4 +37,8 @@ public HouseBuilder addRoof() { house.addRoof(new Roof(roofMaterial)); return this; } + public House build() { + System.out.println("Nail everything together"); + return house; + } } \ No newline at end of file