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"
class="com.myapp.OsFactoryBean">
<constructor-arg index="0" value="myWindow"/>
<constructor-arg index="1" value="com.myapp.Window"/>
</bean>

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

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


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 "myWindow.windows" 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".