Skip to content

Instantly share code, notes, and snippets.

@nickofc
Created September 4, 2019 15:19
Show Gist options
  • Save nickofc/37aea7a42dc9d6e3b7f871fd73f9343b to your computer and use it in GitHub Desktop.
Save nickofc/37aea7a42dc9d6e3b7f871fd73f9343b 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