Giter Site home page Giter Site logo

winforms-mvp's Introduction

Passive view Model-View-Presenter in Windows Forms

There are remarkably few straightforward, minimal examples of the Passive view (or Humble dialog) variety of the Model-View-Presenter pattern for Windows Forms.

This project aims to fill the gap.

The common MVVM way of using INotifyPropertyChanged to connect the model to the view and have no presenter or the presenter as a bystander takes us to the Supervising Controller land. Here, by design, everything is managed by the Presenter instead.

The design is as follows:

MVP class diagram

winforms-mvp's People

Contributors

mrts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winforms-mvp's Issues

Should the View rather not know about Presenter?

First of all, many thanks Mart for putting this repo together, very useful.

The comment I have, should the View rather not know anything about Presenter? Here you have a reference to CustomerPresenter inside ICustomerView:

Presenter.CustomerPresenter Presenter { set; }

I'd expect to have no tight coupling here. Rather, some sort of event sources or observables that the Presenter would be subscribing to. Something similar to what Mark Heath is doing in his related article:

interface ICustomerView
{
    // ...
    int SelectedCustomer { get; set; }
    // ...
    event EventHandler SelectedCustomerChanged;
}

How are the presenter and view connected initially?

Maybe I'm missing it, but I see that the presenter is created , but never passed into the view? How are the presenter and view connected initially?

In Program.cs, do you need to set the presenter property before running the form?

Dependency injection

Hello,

Could you be kind enough to provide a fast/simple example on how would someone add dependency injection to this concept?

I fail to figure out how it's gonna work in WinForms.

Thank you!

Testing business logic inside button event

Just a preface, I am still learning how to unit test and still learning the MVP pattern and its different flavors, so apologies in advanced.

I noticed you have a unit test around saving a customer, which is ultimately called by the button event (editButton_Click). This becomes awkward because you can't test all the code in the button click, just the save customer. I realize this is a basic example, but lets say I want test that edit logic.

I noticed other implementations may wrap an event around the button click in the interface to expose the event:
ICustomerView

event EventHandler EditButtonClick;

CustomerForm

public event EventHandler EditButtonClick
{
    add { this.editButton.Click += value; }
    remove { this.editButton.Click -= value; }
}

CustomerPresenter

_view.EditButtonClick += (s, e) => { /*logic here, need references to edit mode and textbox.readonly*/  }

However exposing the editmode property and the readonly property of the textboxes feels messy...

So without going to far down this rabbit hole, what do you think is the best way to go about refactoring so you could unit test this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.