/winforms-architecture-patterns

A simple WinForms app built using different architectural patterns

Primary LanguageC#

WinForms architecture patterns

A simple WinForms app (a very basic password manager) built using different architectural patterns:

  • Plain: everything is in the views' code behind files.

    • Pros: easiest approach.
    • Cons: no separation of concerns. Difficult to maintain as the apps grows. Untestable.
  • Layered: data access code is in a separate layer.

    • Pros: separates the main concerns. Not too complicated. Some parts of the app are testable.
    • Cons: the view code is still big and hard to test.
  • MVP with Passive View: follows the Model-View-Presenter pattern, Passive View-style.

    • Pros: concerns are clearly separated. Most of the app is testable, including UI logic code (in presenters).
    • Cons: complicates the architecture. Presenter<->View data sync is tedious. A bit overkill for some projects.

Disclaimer:

  • Software architecture is all tradeoffs and compromises. I made some choices to keep things accessible. There are tons of other ways to build WinForms apps and apply these patterns (see resources for some alternatives).
  • Complex architectures offer most benefits in big projects, unlike this one.
  • I am no C# guru. Feel free to notify me of any mistake or suboptimal code.

Some useful resources: