Ch3. 데코레이터 패턴 : 객체 꾸미기
Last updated
Last updated
public abstract class Beverage {
String description = "제목 없음";
public String getDescription() {
return description;
}
public abstract double cost();
}public abstract class CondimentDecorator extends Beverage {
Beverage beverage; // 각 데코레이터가 감쌀 음료를 나타내는 Beverage 객체 지정
public abstract String getDescription();
}public class Espresso extends Beverage {
public Espresso() {
description = "에스프레소";
}
public double cost() {
return 1.99.
}
}public class HouseBlend extends Beverage {
public HouseBlend() {
description = "하우스 블렌드 커피";
}
public double cost() {
return .89;
}
}public class Mocha extends CondimentDecorator {
public Mocha(Beverage beverage) {
this.beverage = beverage;
}
public String getDescription() {
return beverage.getDescription() + "모카";
}
public double cost() {
return beverage.cost() + .20;
}
}