コード例 #1
0
        public static void Main(string[] args)
        {
            Context context = new Context(new OperationAdd());

            Console.WriteLine("10 + 5 = " + context.executeStrategy(10, 5));

            context = new Context(new OperationSubstract());
            Console.WriteLine("10 - 5 = " + context.executeStrategy(10, 5));

            context = new Context(new OperationMultiply());
            Console.WriteLine("10 * 5 = " + context.executeStrategy(10, 5));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Context context;

            // Three contexts following different strategies
            context = new Context(new Add());
            int resultA = context.executeStrategy(3, 4);

            context = new Context(new Multiply());
            int resultB = context.executeStrategy(3, 4);

            Console.WriteLine(string.Format("Result A : {0}", resultA));
            Console.WriteLine(string.Format("Result B : {0}", resultB));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: sinannar/DesignPatterns
        static void Main(string[] args)
        {
            int num1 = 10;
            int num2 = 5;

            Context context = new Context(new OperationAdd());

            Console.WriteLine($"{num1} + {num2} = {context.executeStrategy(num1, num2)}");

            context = new Context(new OperationSubstract());
            Console.WriteLine($"{num1} - {num2} = {context.executeStrategy(num1, num2)}");

            context = new Context(new OperationMultiply());
            Console.WriteLine($"{num1} * {num2} = {context.executeStrategy(num1, num2)}");
        }