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)); }
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); }