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)); }
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)); }
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)}"); }