Created
September 4, 2019 15:19
-
-
Save nickofc/37aea7a42dc9d6e3b7f871fd73f9343b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TaxCalculatorFactory | |
{ | |
public static ITaxCalculator GetForCountry(Country country) | |
{ | |
switch (country) | |
{ | |
case Country.Poland: | |
return new PolandTaxCalculator(); | |
case Country.England: | |
return new EnglandTaxCalculator(); | |
default: | |
throw new ArgumentOutOfRangeException(nameof(country), country, null); | |
} | |
} | |
} | |
public enum Country | |
{ | |
Poland, | |
England | |
} | |
public interface ITaxCalculator | |
{ | |
decimal ComputeTax(decimal price); | |
decimal GetTax(); | |
} | |
public class PolandTaxCalculator : ITaxCalculator | |
{ | |
public decimal ComputeTax(decimal price) | |
{ | |
throw new NotImplementedException(); | |
} | |
public decimal GetTax() | |
{ | |
return 23; | |
} | |
} | |
public class EnglandTaxCalculator : ITaxCalculator | |
{ | |
public decimal ComputeTax(decimal price) | |
{ | |
throw new NotImplementedException(); | |
} | |
public decimal GetTax() | |
{ | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment