一個小問題 TestClient.java

Norberthu5發表於2003-12-24
中: 《23種設計模式的java實現(提供原始碼) 》


builder 模式中:
/*
* A test client to create a house
* but we do not know how the room and door be created
*/
public class TestClient {
public TestClient() {
}

public static void main(String[] args) {
House myHouse = new House(); ----我認為這行是多餘,使人誤解。應該修改為: House myHouse ;當然即使不修改,也沒有任何錯,除了浪費記憶體。
ConcreteHouseBuilderA myHouseBuilder = new ConcreteHouseBuilderA();
HouseDirector myHouseDirector = new HouseDirector();
myHouseDirector.CreateHouse(myHouseBuilder);
myHouse = myHouseBuilder.getHouse();

System.out.println("My house has room :" + myHouse.getRoomNumber());
System.out.println("My house has door :" + myHouse.getDoorNumber());
}
}

相關文章