在Spring框架中使用抽象工厂 [英] Using abstract factory with Spring framework
问题描述
我有一些抽象工厂
public interface AbstractViewersFactory {
IAbstractShapeViewer createRectangle(BaseOperationsListener<RectangleDTO> p);
IAbstractShapeViewer createOval(BaseOperationsListener<OvalDTO> p);
IAbstractShapeViewer createTriangle(BaseOperationsListener<TriangleDTO> p);
}
及其实现 Draw2DViewersFactory . 现在,我想创建一个类,该类将负责按模型创建演示者/查看者并由Spring对其进行配置. 因此,我需要在 .xml 配置中描述应调用的方法. 可能是这样的(伪配置)
And Its implementation Draw2DViewersFactory. Now, I want create some class that will take responsibility for creating presenters/viewers by model and configurate it by Spring. So, I need describe in .xml configuration what method it should call. It can be something like this (pseudo config)
<bean creator>
<constructor-args>
<list>
<bean describe-item> <constructor-args>model=Rectangle.class, method-for-viewer-create="createRectangle"</args>
<bean describe-item> <constructor-args>model=Oval.class, method-for-viewer-create="createOval"</args>
<list>
</constructor-args>
</bean>
我该怎么做?
谢谢.
推荐答案
即使您的问题不清楚,我还是想知道您想知道的内容. 您可以将spring bean定义为工厂实例,然后像下面这样设置该bean的factory方法:
Even though your question is very unclear, I think I got what you wanted to know. You can define a spring bean as a factory instance and then set the factory method of this bean like this:
<bean id="myFactoryBean"
class="AbstractViewersFactory">
<bean id="exampleBean"
factory-bean="myFactoryBean"
factory-method="createRectangle"/>
希望这会有所帮助. 在Google上获取更多信息:p
Hope this helps. Google this for further information :p
问候
这篇关于在Spring框架中使用抽象工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!