public Class MyClass1{ private ParentClass1 parentInstance; private int i=1; public MyClass1(ParentClass1 instance) { this.parentInstance=instance; } public int getI() { return i; } public void setI(int i) { this.i = i; } }
Now we have five child classes that extend ParentClass1. Now in spring, when compiling MyClass1, how will we determine which of the five child instances to enter here (since this depends on some runtime parameter, depending on which we should create the child instance, for example, if I = 1 create an instance of child1 if i = 2 create an instance of child2). Please guide me if there is a way to configure ie spring -config.xml configuration file for the above script?
Edit: -
My question is how do we pass the argument in the factory method. At the same time, this parameter starts from a certain value selected by the user in the user interface and does not know when configuring the configuration file. Below is My factory, client and configuration file
Public class MYFactory { Public static getObject(int i) { if(i==1) { return childclass1;
}
Below is a snippet of code from the configuration file
<bean id="myfactory" class="package.MyFactory" factory-method="getObject"> </bean>
// I know that we can provide the constructor argument above, but it will be static. This argument must come from the value of the user selected in the user interface.
// Below is my client method
public static void main(String arrgs[]) { ParentClass pc=(ParentClass)XMLBeanFactor.getbean("myfactory");
Now, how do I pass the value of i from the main method to the factory method, looking at the example above?
source share