void ExecuteCalculate()
 {
     DisplayValue = MathOperations.Calculate(tempDataForCalculation, mathOperator, DisplayValue)
                    .ToString();
     tempDataForCalculation = "";
     mathOperator           = null;
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("### Open Closed Principle => START ###");
            Console.WriteLine("");

            // main class
            var mo = new MathOperations {
                X = 6, Y = 3
            };

            // main class' operations
            Console.WriteLine("{0} + {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a + b));
            Console.WriteLine("{0} * {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a * b));
            Console.WriteLine("{0} / {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a / b));
            Console.WriteLine("{0} - {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a - b));

            Console.WriteLine("");
            Console.WriteLine("### END ###");
            Console.WriteLine("");
            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("### Liskow Substitution Principle => START ###");
            Console.WriteLine("");

            // main class
            var mo = new MathOperations {
                X = 6, Y = 3
            };

            // main class' operations
            var validators = new List <Validator> {
                new GraterThenZeroValidator(), new NoRestDivideValidator()
            };
            var isValid = true;

            foreach (var v in validators)
            {
                isValid = v.Validate(mo.X, mo.Y);
            }

            if (!isValid)
            {
                Console.WriteLine("Validation failed!");
                Console.WriteLine("");
            }
            else
            {
                Console.WriteLine("{0} + {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a + b));
                Console.WriteLine("{0} * {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a * b));
                Console.WriteLine("{0} - {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a - b));
                Console.WriteLine("{0} / {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a / b));
            }

            Console.WriteLine("");
            Console.WriteLine("### END ###");
            Console.WriteLine("");
            Console.ReadKey();
        }
        void ExecuteSelectOperator(string selectedOperator)
        {
            mathOperator = selectedOperator;

            if (!string.IsNullOrEmpty(tempDataForCalculation))
            {
                DisplayValue = MathOperations.Calculate(tempDataForCalculation, mathOperator, DisplayValue)
                               .ToString();
                tempDataForCalculation = "";
                mathOperator           = null;
            }

            startCalculation = true;
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("### Liskow Substitution Principle => START ###");
            Console.WriteLine("");

            // main class
            var mo = new MathOperations {
                X = 2, Y = 3
            };

            // main class' operations
            var validator = new Validator();

            if (!validator.AreParameterGreaterThenZeroValidation(mo))
            {
                Console.WriteLine("Parameter are not greater then 0!");
            }
            else
            {
                Console.WriteLine("{0} + {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a + b));
                Console.WriteLine("{0} * {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a * b));
                Console.WriteLine("{0} - {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a - b));

                if (validator.ValidateDivideOperation(mo))
                {
                    Console.WriteLine("{0} / {1} = {2}", mo.X, mo.Y, mo.Calculate((a, b) => a / b));
                }
                else
                {
                    Console.WriteLine("Divide with rest is not allowed!");
                }
            }
            Console.WriteLine("");
            Console.WriteLine("### END ###");
            Console.WriteLine("");
            Console.ReadKey();
        }