static void Main(string[] args) { RedColor red = new RedColor(); Circle circle = new Circle(red); circle.Draw(); Console.ReadKey(); }
static void Main(string[] args) { // scoped to allow for re-use of variable names { // First create a concrete shape, since we need one to be able to decorate anything var circle = new Circle(); circle.Draw(); Console.WriteLine(); // Now we decorate the shape with a red color var red = new RedColor(circle); red.Draw(); Console.WriteLine(); // Since the decorator itself is an IShape, we can further decorate it var blueBorder = new BlueBorder(red); blueBorder.Draw(); Console.WriteLine(); // And can continue to decorate each ShapeDecorator with as many decorator classes as we like var huge = new HugeSize(blueBorder); huge.Draw(); Console.WriteLine(); } { // Always must start with a concrete IShape implementation var rect = new Rectangle(); rect.Draw(); Console.WriteLine(); // Note that the order in which we decorate doesn't matter var blueBorder = new BlueBorder(rect); blueBorder.Draw(); Console.WriteLine(); var huge = new HugeSize(blueBorder); huge.Draw(); Console.WriteLine(); var red = new RedColor(huge); red.Draw(); Console.WriteLine(); } }
public static void Main() { Color blue = new RedColor(); Color red = new BlueColor(); var factory = new ColorFactory(); var existingColor = factory.GetColor("blue"); existingColor.Display(); var newColor = factory.GetColor("red"); newColor.Display(); }
static void Main(string[] args) { Console.WriteLine("Decorator Pattern !"); var circle = new CircleShape(); var redCircle = new RedColor(circle); var square = new SquareShape(); var blueSquare = new BlueColor(square); redCircle.Draw(); blueSquare.Draw(); Console.ReadLine(); }
public void Process_ProperOverloadOfMethodIsChoosen() { var processor = new Processor(); var listOfTuples = new List<Tuple<IColorable, IColorable, string>>(); IColorable redColor = new RedColor(); IColorable greenColor = new GreenColor(); listOfTuples.Add(Tuple.Create(greenColor, redColor, "GreenRed")); listOfTuples.Add(Tuple.Create(redColor, greenColor, "RedGreen")); listOfTuples.Add(Tuple.Create(greenColor, greenColor, "GreenGreen")); listOfTuples.Add(Tuple.Create(redColor, redColor, "RedRed")); foreach (var tuple in listOfTuples) { var firstColor = tuple.Item1; var secondColor = tuple.Item2; var expectedColotCombination = tuple.Item3; var actualColorCombination = processor.Process(firstColor, secondColor); Assert.AreEqual(expectedColotCombination, actualColorCombination); } }
public void Process_ProperOverloadOfMethodIsChoosen() { var processor = new Processor(); var listOfTuples = new List <Tuple <IColorable, IColorable, string> >(); IColorable redColor = new RedColor(); IColorable greenColor = new GreenColor(); listOfTuples.Add(Tuple.Create(greenColor, redColor, "GreenRed")); listOfTuples.Add(Tuple.Create(redColor, greenColor, "RedGreen")); listOfTuples.Add(Tuple.Create(greenColor, greenColor, "GreenGreen")); listOfTuples.Add(Tuple.Create(redColor, redColor, "RedRed")); foreach (var tuple in listOfTuples) { var firstColor = tuple.Item1; var secondColor = tuple.Item2; var expectedColotCombination = tuple.Item3; var actualColorCombination = processor.Process(firstColor, secondColor); Assert.AreEqual(expectedColotCombination, actualColorCombination); } }
public static void Main(string[] args) { Policy basic = new Basic(); Console.WriteLine($"{basic.GetDescription()}, ${basic.GetCost()}"); Policy plus = new Plus(); Console.WriteLine($"{plus.GetDescription()}, ${plus.GetCost()}"); Policy silver = new Silver(); Console.WriteLine($"{silver.GetDescription()}, ${silver.GetCost()}"); Policy gold = new Gold(); Console.WriteLine($"{gold.GetDescription()}, ${gold.GetCost()}"); Policy policy1 = new Gold(); policy1 = new AutomaticCar(policy1); policy1 = new BigEngine(policy1); policy1 = new RedColor(policy1); policy1 = new YoungDriver(policy1); Console.WriteLine($"{policy1.GetDescription()}, ${policy1.GetCost()}"); Policy policy2 = new Plus(); policy2 = new AdditionalDriver(policy2); policy2 = new AdditionalDriver(policy2); //second additional driver policy2 = new RedColor(policy2); policy2 = new ManualCar(policy2); Console.WriteLine($"{policy2.GetDescription()}, ${policy2.GetCost()}"); Console.ReadLine(); }
public ConsoleLoggerMiddleware(Printer printer, RedColor red) { _printer = printer; _red = red; }
public void ChooseTypeOfColor(RedColor redColor) { ColorCombination += "Red"; }
public string Process(RedColor firstRedColor, RedColor secondRedColor) { return "RedRed"; }
public string Process(RedColor redColor, GreenColor greenColor) { return "RedGreen"; }
public string Process(GreenColor greenColor, RedColor redColor) { return "GreenRed"; }
public string Process(RedColor firstRedColor, RedColor secondRedColor) { return("RedRed"); }
public string Process(RedColor redColor, GreenColor greenColor) { return("RedGreen"); }
public string Process(GreenColor greenColor, RedColor redColor) { return("GreenRed"); }