If I need a single instance, I inject that instance into the object.
If I need a new instance everytime, I create a Factory.
Code:
interface PieFactory{
Pie create();
}
class DefaultPieFactory implements PieFactory{
private String taste;
Pie create(){
return new Pie(taste);
}
}
class PieEater{
private PieFactory pieFactory;
void eat(){
Pie pie = pieFactory.create();
pie.eat();
}
}
<bean id="pieFactory" class="DefaultPieFactory">
<property name="taste" value="appel"/>
</bean>
<bean id="pieEater" class="PieEater">
<property name="pieFactory" ref="pieFactory"/>
</bean>
This solution doesn't tie you into Spring, it also doesn't change the semantics of the object in a very obscure manner, and it is good design.