标签:play unity rac use tor mes span turn style
1 using UnityEngine; 2 3 namespace DecoratorHeadFirst 4 { 5 public abstract class Beverage 6 { 7 public string description = "Unknow Beverage";//public 子类能够继承 8 9 public string GetDescription() 10 { 11 return description; 12 } 13 14 public abstract double cost(); 15 } 16 17 public class HouseBlend : Beverage 18 { 19 public HouseBlend() 20 { 21 description = "HouseBlend";//父类变量description,c#中声明public才能继承,java则不用 22 } 23 public override double cost() 24 { 25 return 0.89; 26 } 27 } 28 public class DarkRoast : Beverage 29 { 30 public DarkRoast() 31 { 32 description = "DarkRoast"; 33 } 34 public override double cost() 35 { 36 return 0.99; 37 } 38 } 39 public class Espresso : Beverage 40 { 41 public Espresso() 42 { 43 description = "Espresso";//父类变量description,c#中声明public才能继承,java则不用 44 } 45 public override double cost() 46 { 47 return 1.99; 48 } 49 } 50 public class Decaf : Beverage 51 { 52 public Decaf() 53 { 54 description = "Decaf";//父类变量description,c#中声明public才能继承,java则不用 55 } 56 public override double cost() 57 { 58 return 1.05; 59 } 60 } 61 62 63 public abstract class CondimentDecorator : Beverage//抽象类继承不需要实现父类抽象类中的抽象函数 64 { 65 //public abstract new string GetDescription();//加new关键字后与父类函数不同 66 //public abstract string GetDescription(); 67 } 68 public class Milk : CondimentDecorator 69 { 70 Beverage beverage; 71 public Milk(Beverage theBeverage) 72 { 73 beverage = theBeverage; 74 description = beverage.GetDescription() + ",Milk"; 75 76 } 77 public override double cost() 78 { 79 return 0.10 + beverage.cost(); 80 } 81 82 83 } 84 public class Mocha : CondimentDecorator 85 { 86 Beverage beverage; 87 public Mocha(Beverage theBeverage) 88 { 89 beverage = theBeverage; 90 description = beverage.GetDescription() + ",Mocha"; 91 92 } 93 94 public override double cost() 95 { 96 return 0.20 + beverage.cost(); 97 } 98 99 } 100 public class Soy : CondimentDecorator 101 { 102 Beverage beverage; 103 public Soy(Beverage theBeverage) 104 { 105 beverage = theBeverage; 106 description = beverage.GetDescription() + ",Soy"; 107 } 108 109 public override double cost() 110 { 111 return 0.15 + beverage.cost(); 112 } 113 114 } 115 public class Whip : CondimentDecorator 116 { 117 Beverage beverage; 118 public Whip(Beverage theBeverage) 119 { 120 beverage = theBeverage; 121 description = beverage.GetDescription() + ",Whip"; 122 } 123 124 public override double cost() 125 { 126 return 0.10 + beverage.cost(); 127 } 128 129 } 130 }
标签:play unity rac use tor mes span turn style
原文地址:https://www.cnblogs.com/caedmom/p/9268909.html