Skip to content

Instantly share code, notes, and snippets.

@nickofc
Created September 4, 2019 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickofc/aac394c590b738fac4a92364a31e034e to your computer and use it in GitHub Desktop.
Save nickofc/aac394c590b738fac4a92364a31e034e to your computer and use it in GitHub Desktop.
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