|
@@ -2,6 +2,7 @@ package com.sf.javase.io.pattern;
|
|
|
|
|
|
import com.sf.javase.io.pattern.decorator.Chocolate;
|
|
|
import com.sf.javase.io.pattern.decorator.Decorator;
|
|
|
+import com.sf.javase.io.pattern.decorator.Soy;
|
|
|
import com.sf.javase.io.pattern.decorator.Sugar;
|
|
|
import com.sf.javase.io.pattern.drink.Coffee;
|
|
|
import com.sf.javase.io.pattern.drink.Drink;
|
|
@@ -12,20 +13,28 @@ public class CofferBar {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
// 售卖咖啡时 生成了一笔订单 订单中包含饮品+小料
|
|
|
- Drink coffee = new Coffee();
|
|
|
+ // 单独售卖咖啡
|
|
|
+ Drink coffee = new Coffee("摩卡",12);
|
|
|
System.out.println(coffee.getDescription());
|
|
|
System.out.println(coffee.cost());
|
|
|
|
|
|
+ System.out.println("=========");
|
|
|
// 加了小料的咖啡
|
|
|
Decorator chocolateCoffee = new Chocolate(coffee);
|
|
|
System.out.println(chocolateCoffee.getDescription());
|
|
|
System.out.println(chocolateCoffee.cost());
|
|
|
|
|
|
System.out.println("=========");
|
|
|
-
|
|
|
- Drink milk = new Milk();
|
|
|
+ Drink milk = new Milk("这是贵的牛奶",15);
|
|
|
Decorator sugarMilk = new Sugar(milk);
|
|
|
System.out.println(sugarMilk.getDescription());
|
|
|
- System.out.println(sugarMilk.cost());;
|
|
|
+ System.out.println(sugarMilk.cost());
|
|
|
+
|
|
|
+ System.out.println("=========");
|
|
|
+ // 加了咖啡豆的咖啡
|
|
|
+ Drink blackCoffee = new Coffee("黑咖啡",14);
|
|
|
+ Decorator decorator = new Soy(blackCoffee);
|
|
|
+ System.out.println(decorator.getDescription());
|
|
|
+ System.out.println(decorator.cost());
|
|
|
}
|
|
|
}
|