Skip to content

Instantly share code, notes, and snippets.

@hatelove
Last active June 19, 2017 07:39
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 hatelove/e556a97830b54eea76c4945021f3af3e to your computer and use it in GitHub Desktop.
Save hatelove/e556a97830b54eea76c4945021f3af3e to your computer and use it in GitHub Desktop.
Factory Method sample code
public class Blackcat_V2 : IShipper
{
private double _discount;
private Blackcat_V2()
{
}
public static IShipper CreateBlackcatV2(double discount)
{
var blackcatV2 = new Blackcat_V2();
blackcatV2.SetDiscount(discount);
return blackcatV2;
}
private void SetDiscount(double discount)
{
this._discount = discount;
}
public double CalculateFee()
{
return 100 * this._discount;
}
}
public interface IShipper
{
double CalculateFee();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment