/* 
 * 场景描述：
 *
 * 由于你长时间工作，经常需要喝咖啡来提神。
 * 咖啡本身很苦，可加牛奶，也可加糖，或者都加。
 * 试试装饰器来装饰你的咖啡。
 *
 */

// TODO..

@@ -94,8 +94,1464 @@
  TODO..%0A
+interface ICoffee %7B%0A%09void showCoffee();%0A%0A%09float showPrice();%0A%7D%0A%0A//%E5%8E%9F%E5%A7%8B%E5%92%96%E5%95%A1%0Aclass Coffee implements ICoffee %7B%0A%09private String name;%0A%09private float price;%0A%0A%09public Coffee(String name, float price) %7B%0A%09%09this.name = name;%0A%09%09this.price = price;%0A%09%7D%0A%0A%09@Override%0A%09public void showCoffee() %7B%0A%09%09System.out.println(name + %22 coffee%22);%0A%09%7D%0A%0A%09@Override%0A%09public float showPrice() %7B%0A%09%09return price;%0A%09%7D%0A%7D%0A%0A//%E6%8A%BD%E8%B1%A1%E8%A3%85%E9%A5%B0%E5%99%A8%0Aabstract class Decorator implements ICoffee %7B%0A%09private ICoffee coffee;%0A%0A%09public void setCoffee(ICoffee coffee) %7B%0A%09%09this.coffee = coffee;%0A%09%7D%0A%0A%09@Override%0A%09public void showCoffee() %7B%0A%09%09coffee.showCoffee();%0A%09%7D%0A%0A%09@Override%0A%09public float showPrice() %7B%0A%09%09return coffee.showPrice();%0A%09%7D%0A%7D%0A%0A//%E5%8A%A0%E7%B3%96%E5%92%96%E5%95%A1%0Aclass Sugar extends Decorator %7B%0A%09@Override%0A%09public void showCoffee() %7B%0A%09%09System.out.println(%22%E5%8A%A0%E7%B3%96%22);%0A%09%09super.showCoffee();%0A%09%7D%0A%0A%09@Override%0A%09public float showPrice() %7B%0A%09%09return super.showPrice() + 5;%0A%09%7D%0A%7D%0A%0A//%E8%A1%A5%E5%85%A8,%E5%8A%A0%E7%89%9B%E5%A5%B6%E7%9A%84%E5%92%96%E5%95%A1%0Aclass SugarMilk extends Decorator %7B%0A%09@Override%0A%09public void showCoffee() %7B%0A%09%09System.out.println(%22%E5%8A%A0%E7%89%9B%E5%A5%B6%22);%0A%09%09super.showCoffee();%0A%09%7D%0A%0A%09@Override%0A%09public float showPrice() %7B%0A%09%09return super.showPrice() + 10;%0A%09%7D%0A%7D%0A%0Apublic class Main %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09Coffee coffee = new Coffee(%22%E6%8B%BF%E9%93%81%22, 20);%0A%09%09//%E5%8A%A0%E7%B3%96%0A%09%09Decorator sugar = new Sugar();%0A%09%09sugar.setCoffee(coffee);%0A%09%09System.out.println(sugar.showPrice());%0A%09%09%0A%09%09//%E8%A1%A5%E5%85%A8,%E5%8A%A0%E7%B3%96,%E5%8A%A0%E7%89%9B%E5%A5%B6%E7%9A%84%E5%92%96%E5%95%A1%0A%09%09Decorator sugerMilk = new SugarMilk();%0A%09%09sugerMilk.setCoffee(coffee);%0A%09%09System.out.println(sugerMilk.showPrice());%0A%09%7D%0A%0A%7D%0A%0A

add Decorator