• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 軟件測試開發技術.NET設計模式:工廠方法模式(Factory Method)[2]

    發表于:2009-09-03來源:作者:點擊數: 標簽:軟件測試MethodFactoryNetNET
    軟件 測試 開發技術 .NET設計模式:工廠方法模式(Factory Method)[2] .NET開發 關鍵字:設計模式 1/**//// summary 2/// 日志記錄類 3/// /summary 4public class Log 5 { 6 7 public void WriteEvent() 8 { 9 Console.WriteLine("EventLog Success!"); 10
    軟件測試開發技術.NET設計模式:工廠方法模式(Factory Method)[2].NET開發

    關鍵字:設計模式 1/**//// <summary>
     2/// 日志記錄類
     3/// </summary>
     4public class Log
     5    {
     6
     7        public void WriteEvent()
     8        {
     9            Console.WriteLine("EventLog Suclearcase/" target="_blank" >ccess!");
    10        }
    11   
    12        public void WriteFile()
    13        {
    14            Console.WriteLine("FileLog Success!");
    15        }
    16
    17        public void Write(string LogType)
    18        {
    19            switch(LogType.ToLower())
    20            {
    21                case "event":
    22                    WriteEvent();
    23                    break;
    24
    25                case "file":
    26                    WriteFile();
    27                    break;
    28
    29                default:
    30                    break;
    31            }
    32        }
    33    }
    34

        這樣的程序結構顯然不能符合我們的要求,如果我們增加一種新的日志記錄的方式DatabaseLog,那就要修改Log類,隨著記錄方式的變化,switch語句在不斷的變化,這樣就引起了整個應用程序的不穩定,進一步分析上面的代碼,發現對于EventLog和FileLog是兩種完全不同的記錄方式,它們之間不應該存在必然的聯系,而應該把它們分別作為單獨的對象來對待。


     1/**//// <summary>
     2/// EventLog類
     3/// </summary>
     4public class EventLog
     5{
     6    public void Write()
     7    {
     8        Console.WriteLine("EventLog Write Success!");
     9    }
    10}
    11
    12/**//// <summary>
    13/// FileLog類
    14/// </summary>
    15public class FileLog
    16{
    17    public void Write()
    18    {
    19        Console.WriteLine("FileLog Write Success!");
    20    }
    21}
    22

    進一步抽象,為它們抽象出一個共同的父類,結構圖如下:

        實現代碼:

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>