Created
July 24, 2015 06:27
-
-
Save aalhour/682a5a7d399f4fccc789 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 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