【发布时间】:2010-07-01 15:55:09
【问题描述】:
我已经实现了这样的抽象工厂
public abstract class AbstractFactory {
private static final Map FACTORIES = new HashMap();
AbstractFactory(FactoryType type) {
FACTORIES.put(type, this);
}
public abstract A getA();
public abstract B getB();
public static AbstractCatalogFactory getFactory(FactoryType type) {
return (AbstractCatalogFactory) FACTORIES.get(type);
}
}
具体工厂必须调用此抽象工厂构造函数,导致每个具体实现都注册在FACTORIES 映射中。我有点担心在构造函数中引用this,因为在构造函数的执行返回之前,this 的值似乎应该是未定义的。
谢谢, 唐
【问题讨论】:
标签: java design-patterns abstract-factory