class 简单工厂模式
{
/// <summary>
/// 这里我们来尝试一下工厂模式..
/// </summary>
/// <param name="args"></param>
public abstract class Food
{
public abstract void Print();
}
public class TomatoScrambledEggs : Food
{
public override void Print()
{
Console.WriteLine("我是西红柿");
}
}
public class ShreddedPorkWithPotatoes : Food
{
public override void Print()
{
Console.WriteLine("我是图都是");
}
}
public abstract class Cread
{
public abstract Food CreadFoor();
}
public class TomatoFactory : Cread
{
public override Food CreadFoor()
{
return new TomatoScrambledEggs();
}
}
public class PotatoesFactor : Cread
{
public override Food CreadFoor()
{
return new ShreddedPorkWithPotatoes();
}
}
static void Main1(string[] args)
{
ConsoleFormate.consoleFormate(() =>
{
Cread TomateFac1 = new TomatoFactory();
Cread PotatoFac2 = new PotatoesFactor();
Food f1 = TomateFac1.CreadFoor();
Food f2 = PotatoFac2.CreadFoor();
f1.Print();
f2.Print();
}, @"简单工厂");
}
}