Esempio n. 1
0
        static void Main(string[] args)
        {
            StartNumber startNUmber                                  = new StartNumber(5);
            IFormula    startMulResult                               = new MulDecorator(startNUmber, 2);
            IFormula    addAndStartMulResult                         = new AddDecorator(startMulResult, 100);
            IFormula    divAndAddAndStartMulResult                   = new DivDecorator(addAndStartMulResult, 12);
            IFormula    subAndDivAndaddAndStartMulResult             = new SubDecorator(divAndAddAndStartMulResult, 3);
            IFormula    mulAndSubAnddivAndaddAndStartMulResult       = new MulDecorator(subAndDivAndaddAndStartMulResult, 4);
            IFormula    addAndMulAndSubAnddivAndaddAndStartMulResult = new AddDecorator(mulAndSubAnddivAndaddAndStartMulResult, 7);

            Console.WriteLine(addAndMulAndSubAnddivAndaddAndStartMulResult.GetFormula());
            Console.WriteLine(addAndMulAndSubAnddivAndaddAndStartMulResult.GetResult());

            startNUmber.ModifyNumber(30);

            Console.WriteLine(addAndMulAndSubAnddivAndaddAndStartMulResult.GetFormula());
            Console.WriteLine(addAndMulAndSubAnddivAndaddAndStartMulResult.GetResult());
        }
 public override double GetResult()
 {
     return(StartNumber.GetResult() * AdditionalNumber);
 }
 public override string GetFormula()
 {
     return(StartNumber.GetFormula() + " * " + AdditionalNumber.ToString());
 }