??????????????????????????????????????
???????????? ???????[ 2013/5/21 14:44:39 ] ????????
????????????е????????????????
????????????????service locator????????????????
public static Object newObject(Class interfaceOrDefaultClass?? Class[] parameterTypes?? Object[] arguments);
???????????????
ImplFactory.newObject(MyInterface.class?? new Class[]{int.class?? String.class}?? new Object[]{new Integer(1)?? "abc"});
???????????????properties????????????????????????????????????????MyInterface????
???磬????????????????????
com.mycompany.MyInterface=com.mycompany.MyInterfaceImpl
??MyInterfaceImpl?????????????
public MyInterfaceImpl(int i?? String s);
?????MyInterfaceImpl????á?
????????????????????????????????????????????????????????????磺
ImplFactory.newObject(DefaultMyInterfaceImpl.class?? new Class[]{int.class?? String.class}?? new Object[]{new Integer(1)?? "abc"});
????????service locator???????????????????????????????????????ioc container???????????????dynamic proxy?????ImplFactory??
??????????£?
MyInterface = serviceFactory.getMyInterface(1?? "abc");
???????????getMyInterface?????????????ServiceFactory???????У???????????getMyInterface()???????????????serviceFactory?????????????????????????????????л?????ioc??????????spring???????????dynamic proxy??????????????????????
?????£?ImplFactory????????????????????ServiceFactory???????e???????????????????????????????????????????????ImplFactory??????????????ServiceFactory???????ImplFactory???????????"abstraction on top of abstraction"??????????????????????????????????????????????????е??????????????????????????????????????????ioc container???棬???????????
ImplFactoryProxy????????????????dynamic proxy??????????????
?????????棬?????????????????????“???????”???????????????棬??????????????????????????????????÷????棬?????????????????????????????????????????dynamic proxy??
????????????????????????java.util.Map???????ImplFactoryProxy?????????????????????????????£?
public class ImplFactoryProxy {
private final Map defaults;
ImplFactoryProxy(Map defaults) {
this.defaults = defaults;
}
...
}
д????ImplFactoryProxy??????????????????????????????Map??????????????ClassLoader.loadResourceAsStream()???????????????package?????properties???????????Properties.load(inputStream)?????Properties?????Properties???????????????ImplFactoryProxy???
??????????????????????????????????
???????????????
?????????????????review?????????????ClassLoader.loadResourceAsStream???????????У?????????????????PropFactory????
????????????????????????????????????????property?????????????????????key???value??????????ε?property???????????key???????????property map??????????????????????
?÷????
PropFactory.getInstance().getProperty("property file name").getPropertyValue("key");
???????????????code base??
???????????????????????????????????????????????????????????????????????PropFactory??????????PropFactory.getInstance()??????????????????????????????????????????????????PropFactory??
?????????dynamic proxy?в????PropFactory?????????????????????????
1????????????????key-value map???????????PropFactory????????????
2??Properties?? ClassLoader.loadResourceAsStream??????jdk?????????????????????????????????IOUtils??????????????
IOUtils:
Properties loadProperties(ClassLoader loader?? String resourceName);
3???????dynamic proxy????self contained??????????????е???????????ImplFactory????κ????????????????????????κβ????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11