抽象类实例化自己的具体类

时间:2015-01-29 10:06:41

标签: java design-patterns olingo

我在阅读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);
    }
  }

0 个答案:

没有答案