static void Main(string[] args) { BevarageBase espresso = new Espresso(); BevarageBase blackTea = new BlackTea(); BevarageBase greenTea = new GreenTea(); PrintBeverage(espresso); PrintBeverage(blackTea); PrintBeverage(greenTea); Console.WriteLine("----------"); BevarageBase capuccino = new SugarCondiment(new MilkCondiment(new Espresso())); PrintBeverage(capuccino); BevarageBase greenTeaWithSugar = new SugarCondiment(new GreenTea()); PrintBeverage(greenTeaWithSugar); Console.ReadKey(); }
public void buyBlackTeaAndHoney() { BlackTea blackTea = new BlackTea(); Honey honey = new Honey(); customer.buy(blackTea); customer.buy(honey); string actual = customer.print(); string expect = "BlackTea(25.00)+Honey(4.50) | Total=29.50"; Assert.AreEqual(expect, actual); }
// 創立物件 // static 函數宣告:讓在主程式中,不需要實體化物件就可以使用 public static Drink CreateDrink(string order) { Drink obj = null; // 讓工廠判斷要實體化哪個物件的部分 // 可以想像成販賣機上的按鈕 switch (order) { case "紅茶": obj = new BlackTea(); break; case "奶茶": obj = new MilkTea(); break; } return(obj); }
static void Main(string[] args) { BeverageBase blackTea = new BlackTea(); BeverageBase greenTea = new GreenTea(); BeverageBase coffee = new Coffee(); Display(blackTea); Display(greenTea); Display(coffee); Console.WriteLine("----------------------"); BeverageBase americano = new Milk(new Coffee()); Display(americano); BeverageBase americanoWithSugar = new Sugar(new Milk(new Coffee())); Display(americanoWithSugar); Console.ReadLine(); }
static void Main(string[] args) { BeveragesBase coffee = new Coffee(); BeveragesBase blackTea = new BlackTea(); BeveragesBase greenTea = new GreenTea(); Console.WriteLine("Standard beverages: "); ShowBeverageInfo(coffee); ShowBeverageInfo(blackTea); ShowBeverageInfo(greenTea); BeveragesBase cappuccino = new MilkAdd(new SugarAdd(new Coffee())); BeveragesBase blackTeaWithSugar = new SugarAdd(new BlackTea()); BeveragesBase hotChocolateWithMilk = new ChocolateAdd(new SugarAdd(new MilkAdd(new Coffee()))); Console.WriteLine("Custom beverages: "); ShowBeverageInfo(cappuccino); ShowBeverageInfo(blackTeaWithSugar); ShowBeverageInfo(hotChocolateWithMilk); Console.ReadLine(); }
static void Main(string[] args) { DrinkBase blackTea = new BlackTea(); PrintDrink(blackTea); DrinkBase BlackTeaWithSugar = new SugarIngredient(new BlackTea()); PrintDrink(BlackTeaWithSugar); DrinkBase latteCofee = new MilkIngredient(new SugarIngredient(new Espresso())); PrintDrink(latteCofee); DrinkBase BlackTeaWithDoubleSugar = new SugarIngredient(new SugarIngredient(new BlackTea())); PrintDrink(BlackTeaWithDoubleSugar); DrinkBase greenTeaWhithSugarSmallSize = new SugarIngredient(new SmallSize(new GreenTea())); PrintDrink(greenTeaWhithSugarSmallSize); DrinkBase hotChololate = new SugarIngredient(new MilkIngredient(new ChocolateIngredient(new NewDrink()))); PrintDrink(hotChololate); Console.Read(); }