コード例 #1
0
ファイル: Program.cs プロジェクト: GLewKK/TMPS
        static void Main(string[] args)
        {
            RedColor red    = new RedColor();
            Circle   circle = new Circle(red);

            circle.Draw();
            Console.ReadKey();
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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();
        }
コード例 #8
0
 public ConsoleLoggerMiddleware(Printer printer, RedColor red)
 {
     _printer = printer;
     _red     = red;
 }
コード例 #9
0
ファイル: Visitor.cs プロジェクト: Confirmit/Students
 public void ChooseTypeOfColor(RedColor redColor)
 {
     ColorCombination += "Red";
 }
コード例 #10
0
ファイル: Processor.cs プロジェクト: Confirmit/Students
 public string Process(RedColor firstRedColor, RedColor secondRedColor)
 {
     return "RedRed";
 }
コード例 #11
0
ファイル: Processor.cs プロジェクト: Confirmit/Students
 public string Process(RedColor redColor, GreenColor greenColor)
 {
     return "RedGreen";
 }
コード例 #12
0
ファイル: Processor.cs プロジェクト: Confirmit/Students
 public string Process(GreenColor greenColor, RedColor redColor)
 {
     return "GreenRed";
 }
コード例 #13
0
ファイル: Processor.cs プロジェクト: taler0n/Students
 public string Process(RedColor firstRedColor, RedColor secondRedColor)
 {
     return("RedRed");
 }
コード例 #14
0
ファイル: Processor.cs プロジェクト: taler0n/Students
 public string Process(RedColor redColor, GreenColor greenColor)
 {
     return("RedGreen");
 }
コード例 #15
0
ファイル: Processor.cs プロジェクト: taler0n/Students
 public string Process(GreenColor greenColor, RedColor redColor)
 {
     return("GreenRed");
 }
コード例 #16
0
ファイル: Visitor.cs プロジェクト: taler0n/Students
 public void ChooseTypeOfColor(RedColor redColor)
 {
     ColorCombination += "Red";
 }