Design Patterns Explained (6) - Abstract Factory
2004-09-21 10:12
232 查看
当你有这样的类结构:
A1, A2,...,An 继承于 A
B1, B2,...,Bn 继承于 B
...
K1, K2,...,Kn 继承于 K
在 Condition_i 的情况下使用 Xi, 当n>=2的时候管理将会很困难, 所以构造这样的 '工厂' 来负责 Condition :
Cond1, Cond2,...,Condn 继承于 Cond
利用 Condi, 可以产生 Ai, Bi,...,Ki, 他们的使用者只需知道 Cond, A,B,...,K 即可, 而不用知道特定的i. 在这里 Cond 就是所谓的 Abstract Factory.
Switches may indicate a need for abstraction.
Intent: You want to have families or sets of objects for particular clients.
Problem: Families of related objects need to be instantiated
Using the Abstract Factory is indicated when the problem domain has different families of objects presentan each family is used under different circumstances.
If you use Java, the Class class will do the job.
相关文章推荐
- 【Design Patterns】How I explained Design Patterns to my wife: Part 1
- 书 Design Patterns Explained 设计模式精解
- Bridge模式 - 《Design patterns Explained》心得
- How I explained Design Patterns to my wife
- 《Design Patterns Explained》之面向对象
- [设计模式]--Design Patterns Explained学习笔记[chap1]
- How I explained Design Patterns to my wife: Part 1
- Design Patterns Explained 学习笔记(The Object-Oriented Paradigm)
- How I explained Design Patterns to my wife: Part 1
- [设计模式]--Design Patterns Explained学习笔记[chap2]
- 如何向妻子解释设计模式 How I explained Design Patterns to my wife: Part 1
- 《Design Patterns Explained》读书笔记(1)
- [设计模式]--Design Patterns Explained学习笔记[chap3]
- 《Design Patterns Explained》读书笔记(1)
- [reprint]How I explained Design Patterns to my wife: Part 1
- How I explained Design Patterns to my wife: Part 1
- How I explained Design Patterns to my wife: Part 1
- [设计模式]--Design Patterns Explained学习笔记[chap4]
- Design Patterns Explained : A New Perspective on Object-Oriented Design
- [译] The Adapter Pattern 适配器模式 from Ch7 of《Design Patterns Explained》