日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

设计模式 之 创建者

發(fā)布時間:2023/12/18 asp.net 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 设计模式 之 创建者 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
很久沒寫設計模式學習筆記了,今天無聊,隨便把以前看的模式的都寫下.

先把代碼帖上來吧.

這個模式,是模擬 西山居的一款游戲,劍俠情緣 來寫的,呵呵,當然,該游戲到底是怎么設計的,我是不知道,只是作為一個例子放到這個地方.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace 建造者
{
??? public interface 地圖
??? {
??????? 路 路
??????? {
??????????? get;
??????????? set;
??????? }
??????? 樹 樹
??????? {
??????????? get;
??????????? set;
??????? }

??????? Color MainColor
??????? {
??????????? get;
??????????? set;
??????? }
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public class 長白山南麓 : 地圖
??? {

??????? private 路 tempRoad;
??????? public 路 路
??????? {
??????????? get
??????????? {
??????????????? return tempRoad;
??????????? }
??????????? set
??????????? {
??????????????? tempRoad = value;
??????????? }
??????? }

??????? private 樹 tempTree;
??????? public 樹 樹
??????? {
??????????? get
??????????? {
??????????????? return tempTree;
??????????? }
??????????? set
??????????? {
??????????????? tempTree = value;
??????????? }
??????? }

??????? private System.Drawing.Color tempMainColor;
??????? public System.Drawing.Color MainColor
??????? {
??????????? get
??????????? {
??????????????? return tempMainColor;
??????????? }
??????????? set
??????????? {
??????????????? tempMainColor = value;
??????????? }
??????? }

???????
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public interface 路
??? {
??????? double Width
??????? {
??????????? get;
??????????? set;
??????? }

??????? double Height
??????? {
??????????? get;
??????????? set;
??????? }

??????? System.Drawing.Color Color
??????? {
??????????? get;
??????????? set;
??????? }
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public class 水泥路 : 路
??? {
??????? #region 路 Members

??????? public double Width
??????? {
??????????? get
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????????? set
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????? }

??????? public double Height
??????? {
??????????? get
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????????? set
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????? }

??????? public System.Drawing.Color Color
??????? {
??????????? get
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????????? set
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????? }

??????? #endregion
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public interface 樹
??? {
??????? System.Drawing.Color Color
??????? {
??????????? get;
??????????? set;
??????? }
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public class 梧桐樹 : 樹
??? {
??????? #region 樹 Members

??????? public System.Drawing.Color Color
??????? {
??????????? get
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????????? set
??????????? {
??????????????? throw new Exception("The method or operation is not implemented.");
??????????? }
??????? }

??????? #endregion
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public interface 地圖創(chuàng)建
??? {
??????? void 創(chuàng)建路();

??????? void 創(chuàng)建樹();

??????? void 設置顏色();

??????? 地圖 地圖對象();???
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
??? public class 長白山南麓地圖創(chuàng)建 : 地圖創(chuàng)建
??? {
??????? private 地圖 長白山南麓地圖;
??????? public 長白山南麓地圖創(chuàng)建()
??????? {
??????????? 長白山南麓地圖 = new 長白山南麓();
??????? }

??????? public void 創(chuàng)建路()
??????? {
??????????? 路 長白山南麓的路 = new 水泥路();
??????????? 長白山南麓地圖.路 = 長白山南麓的路;
??????? }

??????? public void 創(chuàng)建樹()
??????? {
??????????? 樹 長白山南麓的樹 = new 梧桐樹();
??????????? 長白山南麓地圖.樹 = 長白山南麓的樹;
??????? }

??????? public void 設置顏色()
??????? {
??????????? 長白山南麓地圖.MainColor = System.Drawing.Color.White;
??????? }

??????? public 地圖 地圖對象()
??????? {
??????????? return 長白山南麓地圖;
??????? }
??? }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
?

?public class 系統(tǒng)
??? {
??????? 地圖創(chuàng)建 地圖創(chuàng)建;
??????? public 系統(tǒng)(地圖創(chuàng)建 一個地圖創(chuàng)建實例)
??????? {
??????????? 地圖創(chuàng)建 = 一個地圖創(chuàng)建實例;
??????? }

??????? public 地圖 創(chuàng)建地圖()
??????? {

??????????? 地圖創(chuàng)建.創(chuàng)建路();

??????????? 地圖創(chuàng)建.創(chuàng)建樹();

??????????? 地圖創(chuàng)建.設置顏色();

??????????? return 地圖創(chuàng)建.地圖對象();
??????? }
??? }


}


客戶端調用:

?

??????????? 建造者.系統(tǒng) 建造者系統(tǒng) = new 建造者.系統(tǒng)(new 建造者.長白山南麓地圖創(chuàng)建());

??????????
??????????? 建造者.地圖 長白山南麓地圖 = 建造者系統(tǒng).創(chuàng)建地圖();



我很苦惱,按照這樣的做法,怎么越來越象 工廠方法了.
呵呵,也不知道這個模式有沒有寫對.
先把代碼放到這個地方,有時間在研究 創(chuàng)建者? 和工廠方法的區(qū)別.

轉載于:https://www.cnblogs.com/yanchanggang/archive/2007/12/18/1004225.html

總結

以上是生活随笔為你收集整理的设计模式 之 创建者的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。