Skip to content

Instantly share code, notes, and snippets.

@aalhour
Created July 24, 2015 06:27
Show Gist options
  • Save aalhour/682a5a7d399f4fccc789 to your computer and use it in GitHub Desktop.
Save aalhour/682a5a7d399f4fccc789 to your computer and use it in GitHub Desktop.
public enum ToyType { Car = 0, House = 1 };
public static class ToysFactory
{
private static IToy _newToy { get; set; }
public static IToy CreateToy(ToyType type)
{
if (type == ToyType.Car)
{
_newToy = new CarToy();
}
else
{
_newToy = new HouseToy();
}
_newToy.Prepare();
_newToy.Package();
return _newToy;
}
}
/// <summary>
/// TOY PARENT CLASS
/// </summary>
public interface IToy
{
void Prepare();
void Package();
}
/// <summary>
/// CAR TOY
/// </summary>
public class CarToy : IToy
{
public string Label { get; set; }
public CarToy() { Label = "New Car Toy"; }
public void Prepare() { }
public void Package() { }
}
/// <summary>
/// HOUSE TOY
/// </summary>
public class HouseToy : IToy
{
public string Label { get; set; }
public HouseToy() { Label = "New House Toy"; }
public void Prepare() { }
public void Package() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment