我想問一下,類Genotypes
和Individual
的實現是否違反了依賴倒置原則?如果是這樣,如何解決這個問題?這是DIP(SOLID)的有效用法嗎?
下面是代碼:
public interface IGenotype
{
//some code...
}
public abstract class AIndividual
{
// ... some code
public IGenotype Genotype { get; set;} // DIP likes that !
}
public class Individual : AIndividual
{
public Individual()
{
// some code ...
this.Genotype = new Genotype(); // Is this ok in case of DIP?
}
}
public class Genotype : IGenotype
{
// ... some code
}