1. 程式人生 > >結構型模式---裝飾模式(Decorator)

結構型模式---裝飾模式(Decorator)

{
        Beverage coffee
=new Coffee();
        System.out.println(coffee.getDiscription()
+":"+coffee.cost());
        System.out.println(
new CondimentMilk(coffee).getDiscription()+":"+new CondimentMilk(coffee).cost());
        System.out.println(
new CondimentSugar(new CondimentMilk(coffee)).getDiscription()
+":"+new CondimentSugar( new CondimentMilk(coffee)).cost());
        System.out.println(
new CondimentSugar(new CondimentSugar(new CondimentMilk(coffee))).getDiscription()+":"+new CondimentSugar(new CondimentSugar( new CondimentMilk(coffee))).cost());
    }