jeudi 29 janvier 2015

Abstract class instantiate its own concrete class

I came across this while I was reading the Apache Olingo v4 source code. Is this a known pattern to instantiate the concrete class.


What is the advantage or purpose of separating abstract class Odata and concert class ODataImpl when they are bound together in the newInstance() method.



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);
}
}

Aucun commentaire:

Enregistrer un commentaire