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

推荐订阅源

云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
Jina AI
Jina AI
The Cloudflare Blog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
G
GRAHAM CLULEY
Project Zero
Project Zero
博客园_首页
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
Latest news
Latest news
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
S
Securelist
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
IT之家
IT之家
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Last Watchdog
The Last Watchdog
T
Tenable Blog
宝玉的分享
宝玉的分享
S
Secure Thoughts
P
Privacy & Cybersecurity Law Blog
量子位
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - 如斯夫

Windows Azure中的Affinity Group .NET内存管理 .NET程序的运行与内存管理 堆栈和堆 应用程序的装载与运行 字符串匹配算法 – Sunday算法 该怎么教育 COM学习 完成了吗? 技术人员面试流程泳道图 C# 面试题目 单链表中删除重复数据 C# 数据结构 单链表反转 C# 面试算法 人的问题 foreach中的隐式类型转换 C# 点滴 - 枚举 数据库惊魂 没有人能随随便便成功 If you are a new test manager – From google testing blog
创建型模式
如斯夫 · 2010-03-16 · via 博客园 - 如斯夫

1. 简单工厂

特点:根据条件来创建不同的具体产品

simple_factory

2. 工厂方法

特点:有抽象的产品和抽象的工厂,但是这里的工厂只负责生产一样产品,如需多个产品,则需要多个工厂来生产

Factory method

3. 抽象工厂

特点:一个工厂负责生产一系列不同的产品

abstract_factory

4. Builder

特点:使用同样的建造流程来创建不同的产品

builder

示例代码

  1. class Director {
  2.     public Device Construct(DeviceBuilder builder) {
  3.         string xml = builder.GetDescriptorFile();
  4.         builder.LoadDescriptorFile();
  5.         return builder.Simulate();
  6.     }
  7. }
  8.  
  9. /// <summary>
  10. /// This is the product (would be built by builder)
  11. /// </summary>
  12. class Device {
  13. }
  14.  
  15. /// <summary>
  16. /// abstract builder: 与标准的builder不太一致的地方是,这里的buildpart都用了abstract,实际代码可以不用abstract
  17. /// </summary>
  18. class DeviceBuilder {
  19.     public abstract string GetDescriptorFile();
  20.     public abstract void LoadDescriptorFile();
  21.     public abstract Device Simulate();
  22. }
  23.  
  24. /// <summary>
  25. /// Concrete builder
  26. /// </summary>
  27. class CameraBuilder : DeviceBuilder {
  28.     public override string GetDescriptorFile() {
  29.         throw new NotImplementedException();
  30.     }
  31.  
  32.     public override void LoadDescriptorFile() {
  33.         throw new NotImplementedException();
  34.     }
  35.  
  36.     public override Device Simulate() {
  37.         throw new NotImplementedException();
  38.     }
  39. }