您的位置:首页 > 大数据 > 人工智能

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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: