The question is about GoF
interpretation of the Factory pattern.
I have a Tree<SqlRestriction>
where
public interface SqlRestriction{
public String getSql();
}
Now, I need to create an object of the interface called Container:
public interface Container{
//methods
}
Here is one of its implementation:
public class SimpleSqlListContainer implements Container{
private Integer rate;
private String relation;
//GET, SET, CTORs, other methods
}
So, I tend to wrap the objects creation into a factory
public class ContainerFactory{
public Container create(Tree<SqlRestriction> restrinctions){
//impl
}
}
The actual creation as well as proper initialization are going to be performed by traversing the Tree
passed as a parameter.
QUESTION: If I initialize the object that is being created within the factory method, would it be considered good. Or it can mislead other developers? So, in factory method, should we avoid any kind of initialization and just perform the object creation, leaving the initialization to the client.
Aucun commentaire:
Enregistrer un commentaire