Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

java - Using abstract factory with Spring framework

I have some Abstract Factory

public interface AbstractViewersFactory {
    IAbstractShapeViewer createRectangle(BaseOperationsListener<RectangleDTO> p);
    IAbstractShapeViewer createOval(BaseOperationsListener<OvalDTO> p);
    IAbstractShapeViewer createTriangle(BaseOperationsListener<TriangleDTO> p);
}

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>

How I can do it?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Hope this helps. Google this for further information :p

greetings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...