您可以在 Presenter 项目中声明视图接口,在 Views 项目中声明抽象基视图类,如下所示:
(主讲项目)
public interface IView
{
void ShowErrorMessage(string message);
}
public interface IFooView : IView
{
string SomeField { get; set; }
//...
event EventHandler SomethingClicked;
//...
}
public class FooPresenter
{
private readonly IFooView _view;
public FooPresenter(IFooView view)
{
// inject view here
}
public void DoSomething()
{
// error case
_view.ShowErrorMessage("some message");
}
}
(查看项目)
public abstract class BaseView : IView
{
protected void ShowErrorMessage(string message)
{
// implement shared behavior here
}
}
public class FooView : BaseView, IFooView
{
// view specific behavior here
}