public interface IFruit
{
int Weight { get; set; }
string Name { get; set; }
}
public enum FruitType
{
Apple,
Orange
}
public class Apple:IFruit
{
public Apple(int weight,string name)
{
this.Weight = weight;
this.Name = name;
}
public int Weight
{
get;
set;
}
public string Name
{
get;
set;
}
}
public class Orange : IFruit
{
public Orange(int weight, string name)
{
this.Weight = weight;
this.Name = name;
}
public int Weight
{
get;
set;
}
public string Name
{
get;
set;
}
}
public class FruitFactory
{
public IFruit MakeFruit(FruitType fruit)
{
IFruit myFruit = null;
switch (fruit)
{
case FruitType.Apple:
myFruit = new Apple(3, "Apple");
break;
case FruitType.Orange:
myFruit = new Orange(5, "Orange");
break;
default:
break;
}
return myFruit;
}
}