Is it okay to store reference to other presenter in main presenter? Lets assume that I have complex view and one presenter. I want to split it into two presenters. Can I have reference to Presenter2 in Presenter1 and get data by Presenter2's property? Presenter1 handles creating Presenter2
Maybe code will better explain what I want:
using System;
namespace MVP
{
class Program
{
static void Main(string[] args)
{
// App start
IView1 view = new View1();
IView2 view2 = new View2();
Presenter1 presenter = new Presenter1(view, view2);
}
}
interface IView1 { }
class View1 : IView1 { }
interface IView2
{
object Data { get; }
}
class View2 : IView2
{
public object Data
{
get { throw new NotImplementedException(); }
}
}
class Presenter1
{
private readonly IView1 _view;
private readonly Presenter2 _otherPresenter;
// I don't care if it is one form that implements two interfaces or two forms/usercontrols each with one interface
// I just want to split "big" presenter
// It is okay?
public Presenter1(IView1 mainView, IView2 otherView)
{
_view = mainView;
_otherPresenter = new Presenter2(otherView);
}
public void Foo()
{
var data = _otherPresenter.Data;
// Rest of the code
}
}
class Presenter2
{
private readonly IView2 _view;
public Presenter2(IView2 view)
{
_view = view;
}
public object Data
{
get
{
return _view.Data;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire