为抽象工厂方法提供值的正确方法是什么?
例如。
interface IFactory
{
ISomething Create(int runTimeValue);
}
class Factory : IFactory
{
public ISomething Create(int runTimeValue)
{
return new Something(repository, runTimeValue);
}
}
在示例中,存储库是在创建工厂时通过构造函数注入的,但我可以将存储库移动到 IFactory 接口
interface IFactory
{
ISomething Create(IRepository repository, int runTimeValue);
}
class Factory : IFactory
{
public ISomething Create(IRepository repository, int runTimeValue)
{
return new Something(repository, runTimeValue);
}
}
什么被认为是“正确”的做法?设计抽象工厂时应该如何解释?