《设计模式解析》 第11章 Abstract Factory 模式 复习题
Review Questions
Although using "switches" can be a reasonable solution to a problem that requires choosing among alternatives, it caused problems for the driver problem discussed in this chapter.
| |
Why is this pattern named "Abstract Factory"? | |
What are the three key strategies in the Abstract Factory? “找到变化并封装之” “优先利用组合而非继承” “针对接口而不是实现进行设计” | |
In this pattern, there are two kinds of factories.
| |
What are the consequences of the Abstract Factory pattern? 使得对象的创建于对象的使用分离开来,使用者无需关心对象是如何创建的。 |
The Gang of Four says that the intent of the Abstract Factory pattern is to "provide an interface for creating families of related or dependent objects without specifying their concrete classes."
|
Why do you think the Gang of Four call this pattern "Abstract Factory"? Is it an appropriate name for what it is doing? Why or why not? 与工厂方法不同,抽象工厂模式仅仅定义了需要创建的对象的方法,利用抽象定义了对象本身。使用者无需理会具体的实现。 | |
How do you know when to use the Abstract Factory pattern? 1、当希望将某组对象的创建与对象的使用相隔离,因为该组对象有多重的形式。 2、当switch语句相互耦合时,考虑使用抽象工厂来进行解耦。 3、当你希望隐藏对象的创建方法时。 | |
|