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

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
博客园_首页
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
D
Docker
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
量子位
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Blog of Author Tim Ferriss
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
Cloudbric
Cloudbric
博客园 - 司徒正美
H
Help Net Security
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LangChain Blog
Latest news
Latest news
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
博客园 - Franky
S
Security Affairs
W
WeLiveSecurity
F
Full Disclosure
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
美团技术团队
PCI Perspectives
PCI Perspectives
C
Check Point Blog
Spread Privacy
Spread Privacy

博客园 - 青玄鸟

.NET 中优雅处理 Server-Sent Events 请求取消 vue3.0 + ts 实现上传工厂(oss与cos) Dapr 订阅者参数无法正确反序列化问题 .NET 代码整洁手册 Blazor项目通过docker和nginx部署为静态站点的步骤 Moq mock 方法返回null空指针异常 基于接口隔离原则的依赖注入实现 HttpClient with Stream HttpClient partial update HttpClient 基本使用 值对象的封装 只读集合类型属性实现 适配器模式 模板模式 最少知识原则 单例模式 抽象工厂 工厂方法模式 使用 Visual Studio Code创建和执行T-SQL
简单工厂、工厂方法、抽象工厂
青玄鸟 · 2020-03-30 · via 博客园 - 青玄鸟

共同点

实现了将对象的创建与使用解耦

不同点

简单工厂通过封装对象的创建,实现了对象的创建提取到简单工厂的创建方法,使其可以独立变化与复用。工厂方法、抽象工厂通过在高层组件(Creater)定义抽象依赖,根据依赖倒置原则,实现了客户端与具体产品的解耦。

工厂方法:通过在Creater定义抽象的Product,Creater中的代码都根据抽象的Product编写,ConcreteCreater的工厂方法定义的返回值也是抽象的Product,高层组件(Creater)和低层组件(具体Product)都依赖抽象的Product,彼此之间没有相互依赖。

抽象工厂: 客户端只依赖抽象工厂(AbstractFactory)和抽象的成员(AbstractMember),不依赖任何具体的工厂或者成员,具体的工厂类方法的返回值也是抽象的成员(AbstractMember),高层组件(客户端)与低层组件(具体Member类)都依赖抽象的成员(AbstractMember),彼此之间没有相互依赖。

联系

工厂方法模式的工厂方法一般使用简单工厂实现,抽象工厂每个CreateMember方法一般使用工厂模式实现。

抽象工厂接口内的每个方法都负责创建一个具体产品,同时我们使用实现抽象工厂的子类来提供这些具体的做法,所以在抽象工厂中使用工厂方法实现生产方法是相当自然的。