怎么样创建单态的工厂子类?

在运行期创建工厂子类要用Class.newInstance()
它的前提是工厂子类必须有对工厂创建者可见的构造方法
而工厂类又要设计为Singleton,它的构造方法应该是private

那,咋办儿呢?

还有,应该让谁负责创建子类比较优雅?
如果将工厂接口设计为抽象类,其中实现一个getFactoryImp()方法从配置文件中读取参数生成子类,
那么,这个方法也将被它的子类继承,这是比较难看的

使用jive中工厂模式方式:


public static ForumFactory getInstance(Authorization authorization) {
if (factory == null) {
synchronized(initLock) {
if (factory == null) {

String classNameProp =
JiveGlobals.getJiveProperty("ForumFactory.className");
if (classNameProp != null) {
className = classNameProp;
}
try {
//Load the class and create an instance.
Class c = Class.forName(className);
factory = (ForumFactory)c.newInstance();
}
catch (Exception e) {
System.err.println(
"Failed to load ForumFactory class "
+ className +
". Jive cannot function normally.");
e.printStackTrace();
return null;
}
}
}
}
//Now, create a forum factory proxy.
return factory ;
}