当你有这样的类结构:
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.