?
, , api .
API , . , API, .
, IS, DI Ioc, ... , .
- API (, )
- ()
- wrapper ( IoC, impl)
API:
public interface MyAPI {
String doSomething();
}
public interface MyAPIFactory {
MyAPI getImplementationOfMyAPI();
}
public class RedMyAPI implements MyAPI {
public String doSomething() {
return "red";
}
}
public class GreenMyAPI implements MyAPI {
public String doSomething() {
return "green";
}
}
public class BlackMyAPI implements MyAPI {
public String doSomething() {
return "black";
}
}
. factory .
public class NotFunnyMyAPIFactory implements MyAPIFactory {
private Config config;
public MyAPI getImplementationOfMyAPI() {
if (config.implType == GREEN) {
return new GreenMyAPI();
} else if (config.implType == BLACK) {
return new BlackMyAPI();
} else if (config.implType == RED) {
return new RedMyAPI();
} else {
}
}
}
public class ReflectionMyAPIFactory implements MyAPIFactory {
private Properties prop;
public MyAPI getImplementationOfMyAPI() {
return (MyAPI) Class.forName(prop.get('myApi.implementation.className'))
}
}
factory . ( ... ), .
, .
Spring, , (Spring DI). Spring, ( ).
- my-api.jar (, , ).
- my-api.jar .
- - my-api.jar jap-.
, , , factory, , , , . , api.