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.
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; se开发者_JS百科t; }
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; }
}
精彩评论