工厂模式:所有的对象的创造,都有一个对象去创造
一、一个简单的工厂模式的例子
public class Food
{
public virtual void ShowMe()
{
}
}
public class TomatoFood:Food
{
public override void ShowMe()
{
base.ShowMe();
Print("TomatoFood");
}
}
public class EggFood:Food
{
public override void ShowMe()
{
base.ShowMe();
Print("EggFood");
}
}
public class Factory
{
public Food ShowFactory(string name)
{
if(name=="egg")
{
return new EggFood();
}
else if(name=="tomato")
{
return new TomatoFood();
}
}
}
public
一、一个简单的工厂模式的例子
public class Food
{
public virtual void ShowMe()
{
}
}
public class TomatoFood:Food
{
public override void ShowMe()
{
base.ShowMe();
Print("TomatoFood");
}
}
public class EggFood:Food
{
public override void ShowMe()
{
base.ShowMe();
Print("EggFood");
}
}
public class Factory
{
public Food ShowFactory(string name)
{
if(name=="egg")
{
return new EggFood();
}
else if(name=="tomato")
{
return new TomatoFood();
}
}
}
public