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

推荐订阅源

Engineering at Meta
Engineering at Meta
T
Threatpost
P
Palo Alto Networks Blog
NISL@THU
NISL@THU
O
OpenAI News
Project Zero
Project Zero
G
GRAHAM CLULEY
P
Privacy International News Feed
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
D
Docker
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
W
WeLiveSecurity
P
Proofpoint News Feed
腾讯CDC
Cloudbric
Cloudbric
S
Secure Thoughts
C
Check Point Blog
博客园 - Franky
T
The Exploit Database - CXSecurity.com
T
Troy Hunt's Blog
GbyAI
GbyAI
Security Archives - TechRepublic
Security Archives - TechRepublic
Application and Cybersecurity Blog
Application and Cybersecurity Blog
月光博客
月光博客
C
Cyber Attacks, Cyber Crime and Cyber Security
I
Intezer
TaoSecurity Blog
TaoSecurity Blog
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
F
Fortinet All Blogs
博客园 - 叶小钗
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
C
Cisco Blogs
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 走到天亮

设计模式之“适配器模式” 设计模式之“门面模式” 设计模式之“单例模式” 设计模式之“代理模式” 设计模式之“策略模式” 《C# to IL》第三章 选择和循环 《C# to IL》第二章 IL基础 《C# to IL》第一章 IL入门 淘宝下单高并发解决方案(转载) java linux 配置环境 Spring Aop之(二)--Aop 切面声明和通知 Spring aop Spring RegexpMethodPointcutAdvisor和NameMatchMethodPointcutAdvisor Spring BeanNameAutoProxyCreator 与 ProxyFactoryBean CentOS的IP配置专题 Spring Bean属性绑定Bean返回值 【阿里的感悟】质量该如何做? .(转载) Ubuntu开机自动启动script(2) Ubuntu开机自动启动Script
设计模式之“抽象工厂模式”
走到天亮 · 2013-07-22 · via 博客园 - 走到天亮

抽象工厂模式的优点

        抽象工厂模式除了具有工厂方法模式的优点外,最主要的优点就是可以在类的内部对产品族进行约束。所谓的产品族,一般或多或少的都存在一定的关联,抽象工厂模式就可以在类内部对产品族的关联关系进行定义和描述,而不必专门引入一个新的类来进行管理。

抽象工厂模式的缺点

       产品族的扩展将是一件十分费力的事情,假如产品族中需要增加一个新的产品,则几乎所有的工厂类都需要进行修改。所以使用抽象工厂模式时,对产品等级结构的划分是非常重要的。

适用场景

       当需要创建的对象是一系列相互关联或相互依赖的产品族时,便可以使用抽象工厂模式。说的更明白一点,就是一个继承体系中,如果存在着多个等级结构(即存在 着多个抽象类),并且分属各个等级结构中的实现类之间存在着一定的关联或者约束,就可以使用抽象工厂模式。假如各个等级结构中的实现类之间不存在关联或约 束,则使用多个独立的工厂来对产品进行创建,则更合适一点。

类图:

实例:

Linux 文本框于按钮

windows 文本框于按钮

 #region 抽象工厂模式
    public abstract class AbstractFactory {
        public Food getFood();
        public TableWare getTool();
    }
    public class KetchenFactory : AbstractFactory
    {

        public override Food getFood()
        {
            return new Milk(); 
        }

        public override TableWare getTool()
        {
            return new Spoon();
        }
    }
    public abstract class Food
    {
        public abstract String getEatable();
    }
    public abstract class TableWare
    {
        public abstract String getTool();
    }

    public class Spoon : TableWare
    {
        public String getTool()
        {
            return "spoon";
        }
    }
    public class Milk : Food
    {
        public String getEatable()
        {
            return "milk";
        }
    }
    
    #endregion