Created
September 4, 2019 15:19
-
-
Save nickofc/aac394c590b738fac4a92364a31e034e 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