public void Calculate(Numbers request)
 {
     if (request.GetCalcWanted() == "add")
     {
         Console.WriteLine($"{request.GetNumber1()} + {request.GetNumber2()} = {request.GetNumber1() + request.GetNumber2()}");
     }
     else
     {
         nextInChain.Calculate(request);
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            var chain = new Chain();

            chain.AddToChain(new Addition())
            .AddToChain(new Subtraction())
            .AddToChain(new Multiplication());

            Numbers numbers = new Numbers(5, 10, OperationType.Mul);
            var     result  = chain.Calculate(numbers);

            Console.WriteLine(result);
        }
Exemple #3
0
 public virtual string Calculate(Numbers numbers)
 {
     return(next?.Calculate(numbers));
 }