标签:script null on() 软件 app turn cond int name
软件设计师下午最后一题分析:
namespace ConsoleApplication { #region 2016软考下半年下午最后一题 class Invoice { public virtual void printInvoice() { System.Console.WriteLine("This is invoice content"); } } abstract class Print : Invoice { public Invoice inv; public Print(Invoice t) { inv = t; } public override void printInvoice() { if (inv != null) { //..... inv.printInvoice(); } } } class HeadPrint : Print { public HeadPrint(Invoice t) : base(t) { } public override void printInvoice() { System.Console.WriteLine("This is invoice head"); //... inv.printInvoice(); } } class FootPrint : Print { public FootPrint(Invoice t) : base(t) { } public override void printInvoice() { //... inv.printInvoice(); System.Console.WriteLine("This is invoice foot"); } } #endregion #region 2012软考上半年下午最后一题 abstract class Beverage //饮料 { public string description = "Unknown Beverage"; public virtual string getDescription() { return description; } public abstract int cost(); } abstract class CondimentDecorator : Beverage //配料 { public Beverage beverage; } class Espresso : Beverage //蒸馏咖啡 { private int ESPRESSO_PRICE = 25; public Espresso() { description = "Espresso"; } public override int cost() { return ESPRESSO_PRICE; } } class DarkRoast : Beverage //深度烘培咖啡 { private int DARKROAST_PRICE = 20; public DarkRoast() { description = "DarkRoast"; } public override int cost() { return DARKROAST_PRICE; } } class Mocha : CondimentDecorator //深度烘培咖啡 { private int MOCHA_PRICE = 10; public Mocha(Beverage beverage) { this.beverage = beverage; } public override string getDescription() { return beverage.getDescription() + ", Mocha"; } public override int cost() { return MOCHA_PRICE + beverage.cost(); } } class Whip : CondimentDecorator //奶泡 { private int WHIP_PRICE = 8; public Whip(Beverage beverage) { this.beverage = beverage; } public override string getDescription() { return beverage.getDescription() + ", Whip"; } public override int cost() { return WHIP_PRICE + beverage.cost(); } } #endregion class Program { static void Main(string[] args) { //Beverage beverage = new DarkRoast(); //beverage = new Mocha(beverage); //beverage = new Whip(beverage); //System.Console.WriteLine(beverage.getDescription() + " ¥" + beverage.cost()); Invoice t = new Invoice(); Print second; second = new HeadPrint(t); second.printInvoice(); System.Console.WriteLine("---------"); second = new FootPrint(second); second.printInvoice(); System.Console.ReadKey(); } } }
标签:script null on() 软件 app turn cond int name
原文地址:http://www.cnblogs.com/hellowzl/p/6057731.html