Beispiel #1
0
        public double calculate(TaxCalculationConditions conditions)
        {
            ITaxCalculator taxCalculator = null;

            //Strategy Pattern
            if (conditions.Nationality == Nationality.US)
            {
                taxCalculator = new USTaxCalculator();
            }
            else
            {
                taxCalculator = new CanadaTaxCalculator();
            }
            return(taxCalculator.calculate(conditions));
        }
Beispiel #2
0
        public static ITaxCalculator createCalculator(Nationality nationality)
        {
            ITaxCalculator taxCalculator;

            if (nationality == Nationality.US)
            {
                taxCalculator = new USTaxCalculator();
            }
            else if (nationality == Nationality.Canada)
            {
                taxCalculator = new CanadaTaxCalculator();
            }
            else
            {
                taxCalculator = new EgyptTaxCalculator();
            }
            return(taxCalculator);
        }