C # inheritance with views and presenters

I am working with MVP in ASP.NET and want to see if there is a simpler / cleaner way to do this.

I have a presenter with a presentation. It turns out that I can reuse some presentation properties and presenter methods in other views / presentations in the same area of ​​the application.

Let's say I have a bar that logically is Foo. The main presenter, FooPresenter, has a common logic for Bar and his siblings. The IFoo view also has common properties.

I want to be able to view the view as an IFooView in FooPresenter and the view as an IBarView in BarPresenter and have it in one instance, so I get all the Foo things in my view implementation, aspx p.

Here is what I have:

public interface IFooView {
    // foo stuff
}

public interface IBarView : IFooView {
    // bar stuff
}

public abstract class FooPresenter<T> where T : IFooView {
    public FooPresenter(T view) {
        this.view = view;
    }

    private IFooView view;
    public T View 
    {
        get { return (T)view; }
    }

    public void SomeCommonFooStuff() { }
}

public class BarPresenter : FooPresenter<IBarView> {
    public BarPresenter (IBarView view) 
        : base(view) {

    }

    public void LoadSomeBarStuff() {
        View.Stuff = SomeServiceCall();
    }
}    

- , . , ?

+3
3

, , , - FooPresenter getter private setter.

, .

+1

- , BarPresenter IBarView View {get {return (IBarView) this.view; }}. "" , .

0

T,

    private T view;
0

Source: https://habr.com/ru/post/1722053/


All Articles