简体   繁体   English

通用接口和面向对象结构的最佳实践

[英]best practice for generic interface and object orientation structure

I have an interface that has like 20 Properties that should be implemented all this properties should return an interface type or anything that inherits from this interface, each property of those 20 is returning a diffrent type than the other. 我有一个接口,该接口具有应实现的20个属性,所有这些属性都应返回接口类型或从该接口继承的任何内容,这20个属性的每个属性都将返回一个不同的类型。

Is there a better way than doing the following? 有没有比以下更好的方法?

    public interface IRepository<Product, ProductCategory, Category, ProductImage>
    where Product : IProduct
    where ProductCategory : IProductCategory
    where Category : ICategory
    where ProductImage : IProductImage
{
    IQueryable<Product> Products { get; set; }
    IQueryable<ProductCategory> Products { get; set; }
    IQueryable<Category> Products { get; set; }
    IQueryable<ProductImage> Products { get; set; }
}

i have briefed the code above to only have four generic types in the interface. 我已经简要介绍了上面的代码,以使接口中只有四种通用类型。

Thanks. 谢谢。

Usually, one uses interfaces to avoid tying code to specific concrete types. 通常,人们使用接口来避免将代码绑定到特定的具体类型。

Why can you just write: 为什么只写:

public interface IRepository
{    
    IQueryable<IProduct> Products { get; set; }
    IQueryable<IProductCategory> Products { get; set; }
    IQueryable<ICategory> Products { get; set; }
    IQueryable<IProductImage> Products { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM