我想问一下,类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
}