惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
T
Threat Research - Cisco Blogs
罗磊的独立博客
IT之家
IT之家
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
K
Kaspersky official blog
博客园_首页
T
The Blog of Author Tim Ferriss
T
Tenable Blog
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
D
Docker
TaoSecurity Blog
TaoSecurity Blog
S
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
M
MIT News - Artificial intelligence
U
Unit 42
N
Netflix TechBlog - Medium
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
T
Tailwind CSS Blog
Hacker News: Ask HN
Hacker News: Ask HN
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
美团技术团队
F
Fortinet All Blogs
Last Week in AI
Last Week in AI
AWS News Blog
AWS News Blog
V
V2EX
博客园 - 【当耐特】
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
Schneier on Security
Schneier on Security
腾讯CDC
H
Help Net Security
B
Blog RSS Feed
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
The Last Watchdog
The Last Watchdog
有赞技术团队
有赞技术团队

博客园 - 李明飞

C#设计模式之我见(四)Ⅱ C#设计模式之我见(四)Ⅰ C#设计模式之我见(三)Ⅲ C#设计模式之我见(三)Ⅱ C#设计模式之我见(三)Ⅰ C#设计模式之我见(二)Ⅰ C#设计模式之我见(一) 面向对象编程之重用、继承、多态、抽象 初探SilverLight 2.0的安装和部署 工作小札,生活一杯羹! “管家婆”的好帮手——我的理财小管家 类库DLL属性说明和正确使用App_Code中类的静态成员 冬日糊辣汤 以前的面试题(二) 以前的面试题 SQL Server 2005新特性之感悟 招聘高级网页设计师(北京) 知识点滴(打油篇) Web Services 的设计和模式
C#设计模式之我见(二)Ⅱ
李明飞 · 2011-06-26 · via 博客园 - 李明飞

下面介绍一下建造者模式(Builder Pattern),代码实例如下:
Builder
public abstract class Builder
     {
          public abstract void BuildDoor();
          public abstract void BuildWall();
          public abstract void BuildWindows();
          public abstract void BuildFloor();
          public abstract void BuildHouseCeiling();
      
          public abstract House GetHouse();
     }

Director类:
public class Director
   {
      public void Construct(Builder builder)
       {
            builder.BuildWall();
            builder.BuildHouseCeiling();          
            builder.BuildDoor();
            builder.BuildWindows();
            builder.BuildFloor();         
       }
     }

ChineseBuilder类:
public class ChineseBuilder:Builder
      {
         private House ChineseHouse = new House();
          public override void BuildDoor()
          {
              Console.WriteLine("this Door 's style of Chinese");
          }
          public override void BuildWall()
          {
             Console.WriteLine("this Wall 's style of Chinese");
         }
         public override void BuildWindows()
         {
             Console.WriteLine("this Windows 's style of Chinese");
         }
         public override void BuildFloor()
         {
             Console.WriteLine("this Floor 's style of Chinese");
         }
         public override void BuildHouseCeiling()
         {
             Console.WriteLine("this Ceiling 's style of Chinese");
         }
         public override House GetHouse()
         {
             return ChineseHouse;
         }
     }

阅读全文

posted @ 2011-06-26 12:26  李明飞  阅读(376)  评论()    收藏  举报