I think i am not putting my question correct, please bear with me.
Lets step back and do some real factory example.
i have a singleton Factory class which returns me back a concrete implementaion of Shape interface
So for example i have an interface
public interface Shape(){
public int getArea();
}
Now i have threee concrete classes Circle, Rectangle and Square all implement Shape interface
public class Circle implements Shape{
public int getArea(){
System.out.println("circle area is " + 5);
}
}
public class Rectangle implements Shape{
public int getArea(){
System.out.println("Rectangle area is " + 5);
}
}
public class Square implements Shape{
public int getArea(){
System.out.println("Square area is " + 5);
}
}
Now here my Factory.java will be singleton which will return instance of concrete class in teh factory method
public Class Factory{
//a private constrcutor and a static variable to make the class singleton
public Shape getShape(int i){
if (i ==1){ //return circle
return new Circle();
}else if (i ==2){ //return square
return new Square();
}else { //return rectangle by default
return new Rectangle();
}
}
}
As you see in my above factory getShape method , depending on teh parameter it return the concrete object which implements Shape interface at runtime. i want the same thing with the ServiceFactory i had before. The problem with Spring is that you wire and initiallize everyting before hand and the factory is not able to provide based on a parameter at runtime. Could you please provide how would you implement the Area interace and the concrete Circle, Rectangle and Square factory
pattern in spring.
I will really appreciate it.
Thanks
Rashid