views:

187

answers:

1

I'm trying to create a kind of master/detail UI using an MVP pattern. I have the usual suspects:

interface IMainView{}
class MainView: Form, IMainView{}

interface IMainPresenter{}
class MainPresenter{}

// Numerous domain objects

I also have a UserControl which is also a View of its own MVP triad:

interface ISubView{}
class SubView: UserControl, ISubView{}

interface ISubPresenter{}
class SubPresenter{}

The MainPresenter creates and instance of the SubPresenter, which in turn, creates an instance of SubView. My problem is the Views don't contain references to each other or even know each other exist. They only know about their own presenters but I want to attach one view that is a UserControl to another view that is a Form. Is this possible to do and still maintain each view's ignorance of each other?

Up until this point all the views have exposed the properties needed by each presenter as system types so the presenters would not be affected if a ListBox changed to a ComboBox or a RadioGroup. I'd like to keep it this way if possible but I'm willing to break this pattern if I have no other choice.

My reasons for doing this is the MainView presents the user with a collection of objects. Each object can be one of several (more than 50) different classes. All will implement a common interface but the UI for manipulating each object will vary with the underlying class.

By the way, this is a Winforms application targeting .NET 2.0 (it's compiled as C# 3.0 though)

A: 

I solved this by having the subpresenter pass a reference to its view to the main presenter which then passes it to its view, which then assigns it to an empty panel.

subView
  |
  V
subPresenter
  |
  V
mainPresenter
  |
  V
mainView

It's passed as a plain old object so neither of the presenters need to include references to the winforms namespace. The mainView simply assumes its a decedent of UserControl and casts it as such.

codeelegance