在 Spring 框架中使用抽象工厂 [英] Using abstract factory with Spring framework

查看:23
本文介绍了在 Spring 框架中使用抽象工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些抽象工厂

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的工厂方法:

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"/>

希望这会有所帮助.谷歌这个以获取更多信息:p

Hope this helps. Google this for further information :p

问候

这篇关于在 Spring 框架中使用抽象工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆