考虑到类冗余继承?
public class Category { }
public class Product { }
public interface IService<T> { }
public class ServiceBase<T> : IService<T> { }
public class CategoryService : ServiceBase<Category> { }
public class ProductService : ServiceBase<Product>, IService<Product> { }
是ProductService多余的遗产?只需ServiceBase<Product>
就够了?
这样
static void Main(string[] args) {
Console.WriteLine("CategoryService interfaces:");
foreach(var item in typeof(CategoryService).GetInterfaces()) {
Console.WriteLine(item.Name);
}
Console.WriteLine("ProductService interfaces:");
foreach(var item in typeof(ProductService).GetInterfaces()) {
Console.WriteLine(item.Name);
}
Console.ReadKey();
}
输出
CategoryService interfaces:
IService`1
ProductService interfaces:
IService`1
智能感知诀窍是不是安全的,因为你也可以不实现接口 – digEmAll 2011-03-12 14:36:09
@digEmAll定义相同的方法,但你不会得到一个错误/警告信息,告诉你,你有一个重复的方法,你应该使用'新'关键字,如果你打算重写它,或类似的东西......你知道我在说什么。在任何情况下,如果您确实想要检查/测试以获得问题的答案,请不要在派生类中使用另一种具有相同定义的方法。 :) – Kon 2011-03-12 14:38:33
@Marc,苦多? – Kon 2011-03-12 14:41:45