Пример #1
0
 public void Iterate(FactorialCalculating fc)
 {
     fc.Factorial.Result *= (fc.Steps + 1);
     fc.Steps--;
     Console.WriteLine("Calculating iterated");
     IsReady(fc);
 }
Пример #2
0
 public void Select(FactorialCalculating fc)
 {
     if (fc.Steps > 0)
     {
         Console.WriteLine("Calculating continued");
         NeedIteration(fc);
     }
     else
     {
         Console.WriteLine("Calculating finished");
         IsReady(fc.Factorial);
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            Factorial f1 = new Factorial(5);
            Factorial f2 = new Factorial(3);

            Selector selector = new Selector();
            Invalid  invalid  = new Invalid();
            IsZero   isZero   = new IsZero();
            IsSimple isSimple = new IsSimple();

            FactorialCalculating factorialCalculating = new FactorialCalculating();
            CalculatingSelector  calculatingSelector  = new CalculatingSelector();
            Iterator             iterator             = new Iterator();

            IsReady isReady = new IsReady();

            f1.Initialized += selector.Select;
            f2.Initialized += selector.Select;

            selector.FactorialIsInvalid       += invalid.FactorialIsInvalid;
            selector.FactorialIsSimple        += isSimple.FactorialIsSimple;
            selector.FactorialIsZero          += isZero.FactorialIsZero;
            selector.FactorialNeedCalculating += factorialCalculating.FactorialCalculatingPrepare;

            factorialCalculating.IsReady += calculatingSelector.Select;

            calculatingSelector.NeedIteration += iterator.Iterate;
            iterator.IsReady += calculatingSelector.Select;

            calculatingSelector.IsReady += isReady.FactorialWrite;
            isZero.IsReady   += isReady.FactorialWrite;
            isSimple.IsReady += isReady.FactorialWrite;

            f1.Start();
            f2.Start();
        }