0

I have tried to implement the Passive View MVP in my WinForms application as much as possible. The Presenter is the only one who uses the Model and the Presenter responds to events that are generated in the View. The View in fact is very 'dumb' as it only fires events and deals with the form controls.

Now my question, is it wrong, or very 'anti-pattern' that the View is created with a concrete Model that it then passes to the Presenter?

I need this so that I can test my Presenter properly.

View constructor

public HomeScreenView(IAssessmentModel model)
{
    InitializeComponent();
    homeScreenPresenter = new HomeScreenPresenter(this, model);
}

Presenter's test initialize

[TestInitialize()]
public void TestInitialize()
{
    model = new MockAssessmentsModel();
    view = new MockHomeScreenView(model);
    presenter = view._presenter;
}
2

It seems like you have tried to implement a dependency injection mechanism in the Presenter, but failed to do so in the View.

The point of MVP, especially Passive-View MVP, is that the View is as dumb as possible. When you pass a Model to the View, the View can now address the business layer, which is against the very core purpose of this pattern.

I would suggest you use a dependency injection container. If you insist on hard coding the dependencies, perhaps it would be better to instantiate the Model from the Presenter itself, and minimising the number of chained dependencies.

0

I wouldn't classify it as outright wrong. It is serving a very valid purpose, but I'd rather look at which process is actually responsible for creating the view. If that view is constructed from another presenter it might be feasible to just new up the HomeScreenPresenter from the start and provide that as is to the view. It would require some sort of TakeView method on the presenter to ensure that once the view has been setup that the presenter can pull all the data through to the view. If you do stick with just providing the model to the constructor it would rather be a convention that you'll have to enforce in order to ensure that the view does not operate against the model directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.