public void Run() { Icecream iceCream = new Chocolate(); iceCream = new Fudge(iceCream); iceCream = new Sprinkle(iceCream); Console.WriteLine("Cost of Icecream: " + iceCream.Cost().ToString()); Console.ReadKey(); }
/// <summary> /// Two DnsResourceDataTransactionSignature are equal iff their algorithm time signed, fudge, message authentication code, original ID, error /// and other fields are equal. /// </summary> public bool Equals(DnsResourceDataTransactionSignature other) { return(other != null && Algorithm.Equals(other.Algorithm) && TimeSigned.Equals(other.TimeSigned) && Fudge.Equals(other.Fudge) && MessageAuthenticationCode.Equals(other.MessageAuthenticationCode) && OriginalId.Equals(other.OriginalId) && Error.Equals(other.Error) && Other.Equals(other.Other)); }
static void Main(string[] args) { IceCream iceCream = new Chocolate(); iceCream = new Sprinkle(iceCream); iceCream = new Fudge(iceCream); iceCream = new Blueberries(iceCream); Console.WriteLine(iceCream.Cost()); Console.ReadLine(); }
static void Main(string[] args) { IceCream iceCream = new Vanilla(); iceCream = new Sprinkle(iceCream); iceCream = new Fudge(iceCream); Console.WriteLine(iceCream.Cost()); Console.ReadKey(); }
static void Main(string[] args) { // Que problema ele resolve? // Anexar responsabilidades adicionais a um objeto dinamicamente. // Decoradores fornecem uma alternativa flexível para subclasse para ampliar a // funcionalidade. //Fontes: // https://sourcemaking.com/design_patterns/decorator // https://www.youtube.com/watch?v=nk9Z1vwO3RI IceCream iceCream = new Chocolate(); iceCream = new Sprinkle(iceCream); iceCream = new Fudge(iceCream); Console.WriteLine(iceCream.Cost()); Console.ReadKey(); }
public static void CallDecoratorPattern() { IceCream iceCreamChocolate = new Chocolate(); iceCreamChocolate = new Sprinkle(iceCreamChocolate); iceCreamChocolate = new Fudge(iceCreamChocolate); Console.WriteLine("Chocolate Ice Cream with Sprinkles, Fudge = " + iceCreamChocolate.Cost().ToString("C")); IceCream iceCreamVanilla = new Vanilla(); iceCreamVanilla = new Sprinkle(iceCreamVanilla); iceCreamVanilla = new Fudge(iceCreamVanilla); iceCreamVanilla = new Caramel(iceCreamVanilla); iceCreamVanilla = new WhipCream(iceCreamVanilla); iceCreamVanilla = new WaffleCone(iceCreamVanilla); Console.WriteLine("Vanilla Ice Cream with Sprinkles, Fudge, Caramel, WhipCream, WaffleCone = " + iceCreamVanilla.Cost().ToString("C")); Console.ReadKey(); }