private static void Main(string[] args) { // 初始化做菜的两个工厂() Creator shreddedPorkWithPotatoesFactory = new ShreddedPorkWithPotatoesFactory(); Creator tomatoScrambledEggsFactory = new TomatoScrambledEggsFactory(); // 开始做西红柿炒蛋 AbstractFood tomatoScrambleEggs = tomatoScrambledEggsFactory.CreateFoddFactory(); tomatoScrambleEggs.Print(); //开始做土豆肉丝 AbstractFood shreddedPorkWithPotatoes = shreddedPorkWithPotatoesFactory.CreateFoddFactory(); shreddedPorkWithPotatoes.Print(); // 如果客户又想点肉末茄子了 // 再另外初始化一个肉末茄子工厂 Creator minceMeatEggplantFactor = new MincedMeatEggplantFactory(); // 利用肉末茄子工厂来创建肉末茄子这道菜 AbstractFood minceMeatEggplant = minceMeatEggplantFactor.CreateFoddFactory(); minceMeatEggplant.Print(); Console.Read(); }
static void Main(string[] args) { TomatoScrambledEggsFactory tomatoFactory = new TomatoScrambledEggsFactory(); TomatoScrambledEggs tomato = (TomatoScrambledEggs)tomatoFactory.CreateFood(); tomato.Print(); Console.ReadKey(); }
static void Main(string[] args) { var shreddedPorkWithPotatoesFactory = new ShreddedPorkWithPotatoesFactory(); var tomatoScrambledEggsFactory = new TomatoScrambledEggsFactory(); var tomatoFactory = tomatoScrambledEggsFactory.CreateFoodFactory(); tomatoFactory.Print(); var shreddedFactory = shreddedPorkWithPotatoesFactory.CreateFoodFactory(); shreddedFactory.Print(); }
static void Main(string[] args) { // 初始化做菜的两个工厂() Creator shreddedPorkWithPotatoesFactory = new ShreddedPorkWithPotatoesFactory(); Creator tomatoScrambledEggsFactory = new TomatoScrambledEggsFactory(); // 开始做西红柿炒蛋 Food tomatoScrambleEggs = tomatoScrambledEggsFactory.CreateFoddFactory(); tomatoScrambleEggs.Print(); //开始做土豆肉丝 Food shreddedPorkWithPotatoes = shreddedPorkWithPotatoesFactory.CreateFoddFactory(); shreddedPorkWithPotatoes.Print(); Console.Read(); }