Skip to content

Instantly share code, notes, and snippets.

@vincent1086
Created August 2, 2016 03:59
Show Gist options
  • Save vincent1086/d2a0a0664b30c198b1d69201422e5874 to your computer and use it in GitHub Desktop.
Save vincent1086/d2a0a0664b30c198b1d69201422e5874 to your computer and use it in GitHub Desktop.
Android - Sample Factory
public final class SampleFactory {
private static final Constructor<?> _CONSTRUCTOR;
private static final String _DEFAULT_IMPLEMENTION = "com.example.vincent.customImpl";
static {
Class<?> clazz = null;
String impl = System.getProperty(_DEFAULT_IMPLEMENTION);
if(impl != null){
try{
clazz = Class.forName(impl);
}catch(ClassNotFoundException ignore){
}
}
if(null == clazz){
try{
clazz = Class.forName("com.example.vincent.customImpl");
}catch(ClassNotFoundException e){
throw new AssertionError(e);
}
}
try{
_CONSTRUCTOR = clazz.getCounstructor(CustomConfiguration.class);
}catch(NoSuchMethodException e){
throw new AssertionError(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment