Announcement Announcement Module
No announcement yet.
Defining families of beans (aka AbstractFactory design pattern) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defining families of beans (aka AbstractFactory design pattern)

    I have different families of beans, for example first family contains beans creating Windows objects and the second family creating Linux objects.

    Suppose there is Window interface and implementation for each family: LinuxWindow, WindowsWindow
    To create Window object, I'll use FactoryBean to load the proper implementation (using bean naming convention)

    <!-- Select implementation according to the DB deployment type-->
    <bean id="myWindow" lazy-init="true"
    <constructor-arg index="0" value="myWindow"/>
    <constructor-arg index="1" value="com.myapp.Window"/>

    <bean id="myWindow.linux" class="com.myapp.LinuxWindow" lazy-init="true">

    <bean id="" class="com.myapp.WindowsWindow" lazy-init="true" >

    This way I encapsulate "myWindow" bean: anyone that uses it do not aware about different implementations
    The problem is when there are any request by bean type "Window" (autowiring or getting beans by type from app context): "myWindow.linux" and "" will be exposed.

    Is there any more elegant way to solve this problem? Once one family is selected at runtime, all the other families should stay "hidden".