
you are here
427
11
章
Proxy
パターン
public class GumballMonitor {
GumballMachine machine;
public GumballMonitor(GumballMachine machine) {
this.machine = machine;
}
public void report() {
System.out.println("
ガムボールマシン:
" + machine.getLocation());
System.out.println("
現在の在庫:
" + machine.getCount() + "
個のガムボール
");
System.out.println("
現在の状態:
" + machine.getState());
}
}
public class GumballMachine {
//
他のインスタンス変数
String location;
public GumballMachine(String location, int count) {
//
ここに他のコンストラクタコードが入る
this.location = location;
}
public String getLocation() {
return location;
}
//
ここに他のメソッドが入る
}
モニターのコーディング
次に、別のクラス
GumballMonitor
を作成しましょう。
GumballMonitor
クラス
は、マシンの位置、 ...