谁研究过picocontainer 进来讨论一下!

04-07-26 nickycy
问题1.我觉得国人写的代码和老外写的代码风格真很不一样为什么?

是不是值得深思?欢迎大家发表一下看法!

问题2.picocontainer中

MutablePicoContainer pico = new DefaultPicoContainer();

pico.registerComponentImplementation(Boy.class);

Boy boy = (Boy) pico.getComponentInstance(Boy.class);

谁知道Boy.class最终是在哪里,怎样被实例的?我看了半天看不出!谁知道,请教一下

         

anonymous
2004-07-27 09:11
1、我没觉得有什么不一样的。大家看的都是同样的书,怎么会有多大的风格差异?

2、跟踪getComponentInstance方法,很快就可以找到。

nickycy
2004-07-27 09:40
1。new DefaultPicoContainer()的时候主要是new了DefaultComponentAdapterFactory

2。在regedit的时候用DefaultComponentAdapterFactory创建相关的adapter,同时把boy.class作为参数传入,我跟踪最终好象保存在AbstractComponentAdapter里面,我想regedit阶段boy.class是没有被实例的

3。调用getComponentInstance的时候最终也跟踪到最终的也是调用了getComponentInstance的方法,里面没有boy.class.newinstance()或new boy()的方法啊,那怎么实例?还有第三种实例方式?不可以调用接口的getComponentInstance就能实现吧。8明白什么回事

nickycy
2004-07-27 09:45
在ComponentAdapter接口里有这样的方法和注释

/**

* Retrieve the component instance. This method will usually create a new instance each time it is called, but that

* is not required. For example, {@link org.picocontainer.defaults.CachingComponentAdapter} will always return the

* same instance.

*

* @return the component instance.

* @throws PicoInitializationException if the component could not be instantiated.

* @throws PicoIntrospectionException if the component has dependencies which could not be resolved, or

* instantiation of the component lead to an ambigous situation within the

* container.

*/

Object getComponentInstance() throws PicoInitializationException, PicoIntrospectionException;

怎么可以实例?

nickycy
2004-07-27 10:30
怎么调用接口也能实例,邪!

猜你喜欢
2Go 1 2 下一页