1
votes

I am developing an app with multiple views. Each view is composed of other discrete reusable view components.

Using MVP, how are the subviews created? The parent presenter is easy enough to create using something like this:

var ParentPresenter = new ParentPresenter(model, parentView);

But within the parent presenter, how are the child or sub views created?

Would I instantiate the sub-view presenters within the parent presenter? To do that would require access to concrete sub-view implementations which goes against MVP right? And wouldn't that make it awkward to unit test my presenters?

I've read through many articles, posts, and examples (mostly in .NET) but I'm still not 'getting it'.

Also, I'm doing this in JavaScript (using Backbone), so any specific examples in JS would be helpful.

Thanks

1

1 Answers

0
votes

In .NET I use an IoC container to solve this issue:

SubPresenter constructor:

this.view = IoC.Resolve<ISubView>();

So in application:

IoC.Register<ISubView, ConcreteSubView>();

In unit tests:

IoC.Register<ISubView, MockSubView>();

I dont know about JS, but you can check this thread about IoC frameworks for JS.