Let's say I want to build a list of strings (Which is not the real scenario case, but sounds simpler to explain).
I'd have an interface for my list of strings factory that would look like this
public interface IStringsListFactory{
List<string> Create();
}
But lets say one of my concrete factory would require to get this list of string from a file/database etc..
public class StringsListFromFile : IStringsListFactory{
private StreamReader _streamReader;
public StringsListFromFile(StreamReader sr) //StreamReader is just an example.
{
_streamReader = sr;
}
public List<string> Create(){
///recover the strings using my stream reader...
}
}
I know this approach would work, but I was wondering if it breaks the Factory Pattern to pass parameters to the factory's constructor so I wouldn't break my interface. Are there any counterparts to doing this? Is there another solution I didn't think of? Am I asking too many questions!?! (Yeah, I know the answer to this one!)