我在阅读Apache Olingo v4源代码时遇到过这个问题。这是一个实例化具体类的已知模式。
在newInstance()方法中将抽象类Odata和Conceet类ODataImpl绑定在一起时,分离它们的优点或目的是什么?
public abstract class OData {
private static final String IMPLEMENTATION = "org.apache.olingo.server.core.ODataImpl";
public static OData newInstance() {
try {
final Class<?> clazz = Class.forName(OData.IMPLEMENTATION);
/*
* We explicitly do not use the singleton pattern to keep the server state free
* and avoid class loading issues also during hot deployment.
*/
final Object object = clazz.newInstance();
return (OData) object;
} catch (final Exception e) {
throw new ODataRuntimeException(e);
}
}