- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- namespace Factory
- {
- class CRunMain
- {
- static void Main(string[] args)
- {
- CPizzaStore objFac1 = new CNyPizzaStore();
- CPizzaStore objFac2 = new CChicagoPizzaStore();
- CPizza objPiz1 = objFac1.OrderPizza("cheese");
- CPizza objPiz2 = objFac2.OrderPizza("cheese");
- Console.WriteLine("andy love pizza: " + objPiz1.GetName());
- Console.WriteLine("congfeng love pizza: " + objPiz2.GetName());
- }
- };
- public abstract class CPizzaStore
- {
- public CPizzaStore()
- {
- }
- public CPizza OrderPizza(string strType)
- {
- CPizza objPiz;
- objPiz = this.CreatePizza(strType);
- if (null == objPiz)
- {
- return null;
- }
- Console.WriteLine(objPiz.Prepare());
- Console.WriteLine(objPiz.Bake());
- Console.WriteLine(objPiz.Cut());
- Console.WriteLine(objPiz.Box());
- return objPiz;
- }
- protected abstract CPizza CreatePizza(string strType);
- };
- public abstract class CPizza
- {
- public CPizza()
- {
- this.m_arrToppings = new ArrayList();
- }
- public string Prepare()
- {
- StringBuilder strbld = new StringBuilder();
- strbld.Append("Prepare " + this.m_strName + "/n");
- strbld.Append("Tossing " + this.m_strDough + "/n");
- strbld.Append("Adding " + this.m_strSauce + "/n");
- strbld.Append("Adding toppings:" + "/n");
- foreach (string strTop in this.m_arrToppings)
- {
- strbld.Append("/t" + strTop + "/n");
- }
- return strbld.ToString();
- }
- public virtual string Bake()
- {
- return "bake for 25 minutes at 350/n";
- }
- public virtual string Cut()
- {
- return "cutting the pizza into diagonal slices!/n";
- }
- public virtual string Box()
- {
- return "place pizza in official PizzaStore box!/n";
- }
- public string GetName()
- {
- return this.m_strName;
- }
- protected string m_strName;
- protected string m_strDough;
- protected string m_strSauce;
- protected ArrayList m_arrToppings;
- };
- public class CNyStyleCheesePizza : CPizza
- {
- public CNyStyleCheesePizza()
- {
- this.m_strName = "NY Style Sauce and Cheese Pizza";
- this.m_strSauce = "Martinara Sauce";
- this.m_strDough = "Thin Crust Dough";
- this.m_arrToppings.Add("Greated Reggiano Cheese");
- }
- }
- public class CChicagoStyleCheesePizza : CPizza
- {
- public CChicagoStyleCheesePizza()
- {
- this.m_strDough = "Extra Thick Crust Dough";
- this.m_strName = "Chicago Style Deep Dish Cheese Pizza";
- this.m_strSauce = "Shredded Mozzarella Cheese";
- }
- public override string Cut()
- {
- return "Cutting the pizza into square slices /n";
- }
- }
- public class CChicagoPizzaStore : CPizzaStore
- {
- public CChicagoPizzaStore()
- {
- }
- protected override CPizza CreatePizza(string strType)
- {
- if (strType.Equals("cheese"))
- {
- return new CChicagoStyleCheesePizza();
- }
- return null;
- }
- };
- public class CNyPizzaStore : CPizzaStore
- {
- public CNyPizzaStore()
- {
- }
- protected override CPizza CreatePizza(string strType)
- {
- if (strType.Equals("cheese"))
- {
- return new CNyStyleCheesePizza();
- }
- return null;
- }
- }
- }