我想不出为继承层次结构创建视图方法。如果我像下面的代码一样创建类层次结构,那么我就不能从bview.set(...)中正确使用B类的方法和属性而不进行强制转换,因为BView是从AView继承的。和Set method signature接受A类型的变量,但在BView中我希望设置B类型的变量。我该如何解决我的问题?
public class A
{
public int id;
public int received;
}
public class B:A
{
public DateTime date;
//... other fields and properties
public void SomeMethod();
//... other methods
}
public interface IView<T>
{
T Source{get;}
void Init(T source);
void Display(bool isOn);
bool IsActive();
}
public class AView : IView<A>
{
public A Source{get; private set;}
public void Set(A source){
Source = source;
}
}
public class BView : AView
{
///???
}
谢谢你。:3