烹飪,簡單工廠(Simple Factory)


“烹”就是煮的意思,“飪”是指熟的意思,狹義地說,烹飪是對食物原料進行熱加工,將生的食物原料加工成熟食品;廣義地說烹飪是指對食物原料進行合理選擇調配,加工治凈,加熱調味,使之成為色、香、味、形、質、養兼美的安全無害的、利於吸收、益人健康、強人體質的飯食菜品包括調味熟食,也包括調制生食。

因此,我們產生一個烹飪類: 

Cook
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Cook
/// </summary>
namespace Insus.NET
{
    public class Cook
    {
        public virtual void CookedFood()
        { 
            
        }
    }
}


烹飪的方式有很多:

油傳熱:炒,煎,貼,烹,炸,溜

烹:鹵汁不加淀粉勾芡,余同溜。

生料炒,叫煸。

炒后水傳熱:熬,燴,燜,燒,扒

熬:先把料物炒一炒,然后加湯至熟。調味料可在加湯前或湯后加。

燴:出鍋前勾芡,余同熬。

燜:亦作炆,先炒,然后加湯和調味品,微火,至熟。

燒:加湯和調料后,微火至接近熟,再以旺火收湯。余同燜。

扒:出鍋前勾芡,余同燒。

:將煎或炸過的原料加調料小火制熟的過程,如:大蝦,鯽魚等,具有口感酥爛,汁濃味美的特點。

水傳熱:汆,涮

煮:投料物於水(涼、溫、開),加熱至熟

燉:旺火收湯。余同煮。

煨:主要用於不易酥爛的料物,如腳爪一類。寬湯旺火。

焐:溫火久熱。余同煨。

汽傳熱:蒸,鮓

其它:鹵,醬,熏,烤,熗,腌,拌,拔絲

焗:以鹽為熱介質的烹調方法,如鹽焗雞。成菜具有味醇厚,鮮香味美的特點。

調料:自然粉

 

接下來,我們產生炒,煎,煮,燉等類:

烹飪“炒”類:

Fry
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Fry
/// </summary>
namespace Insus.NET
{
    public class Fry : Cook 
    {
        public Fry()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public override void CookedFood()
        {
            HttpContext.Current.Response.Write("炒方式的食物...");
        }
    }
}


烹飪“煎”類:

PanFry
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for PanFry
/// </summary>
namespace Insus.NET
{
    public class PanFry : Cook 
    {
        public PanFry()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public override void CookedFood()
        {
            HttpContext.Current.Response.Write("煎方式的食物...");
        }
    }
}


烹飪“煮”類:

Boil
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Boil
/// </summary>
namespace Insus.NET
{
    public class Boil : Cook
    {
        public Boil()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public override void CookedFood()
        {
            HttpContext.Current.Response.Write("煮方式的食物...");
        }
    }
}


烹飪“燉”類:

Stew
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Stew
/// </summary>
namespace Insus.NET
{
    public class Stew : Cook
    {
        public Stew()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public override void CookedFood()
        {
            HttpContext.Current.Response.Write("燉方式的食物...");
        }
    }
}

 
簡單烹飪工廠類:

CookFactory
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for CookFactory
/// </summary>
namespace Insus.NET
{
    public class CookFactory
    {
        public static Cook CreateCook(string cookingMethod)
        { 
            Cook cook = null;
            switch (cookingMethod)
            { 
                case "":
                    cook = new Fry();
                    break;
                case "":
                    cook = new PanFry();
                    break;
                case "":
                    cook = new Boil();
                    break;
                case "":
                    cook = new Stew();
                    break;
            }

            return cook;
        }
    }
}


客戶端aspx代碼:

SimpleFactoryDemo.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;

public partial class SimpleFactoryDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Cook cook;
        cook = CookFactory.CreateCook("");  //傳入不同的烹飪方式
        cook.CookedFood(); //得到不同的烹飪食物。
    }
}

 
上面部分文字(字體顏色為靛青色)來自網絡摘錄。



下面內容於2014-12-19 14:44分補充:

最后一個簡單烹飪工廠類(CookFactory),我們可以重構一下Switch方法。由於所switch的字符串與所new的類名完全不一樣,因此沒有辦使用反射。但我們可以使用一個中介者設計模式來解決,創建一個中介者:



然后就可以重構switch分流程序了:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM