当你有这样的类结构:
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.
博客介绍了在类结构管理困难时,构造‘工厂’负责条件判断的方法。利用继承于Cond的Condi产生Ai、Bi等,使用者只需知道Cond、A、B等。还指出在问题域有不同对象族且各家族使用情况不同时适用抽象工厂模式,在Java中Class类可实现。
904

被折叠的 条评论
为什么被折叠?



