抽象ファクトリメソッドに値を提供する正しい方法はどれですか?
例えば。
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);
}
}
これを行う「正しい」方法とは何ですか?抽象ファクトリを設計するときの1つの理由は何ですか?