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

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - Franky
U
Unit 42
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
博客园 - 【当耐特】
罗磊的独立博客
B
Blog
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
爱范儿
爱范儿
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
S
SegmentFault 最新的问题
aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
L
LangChain Blog
T
Tailwind CSS Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
Vercel News
Vercel News
Recent Announcements
Recent Announcements
博客园 - 司徒正美
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
Security Latest
Security Latest
T
Threat Research - Cisco Blogs

博客园 - 李明飞

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)  评论()    收藏  举报