简体   繁体   中英

c# Winforms MVC

I have never used MVC before and would like some advice.

I have actually already written quite a bit of code, but looking at it, it seems to be quite highly coupled between classes and there is a lot of code written on the actual main form of the winform. I am a University student, recently started on a 12 month placement, so do not have much real world experience.

My system is effectively a WinForm GUI that has, amongst other things, a treeview that is popualted at load via an event. And then when the user clicks on a node, it gets a datagridview from a dllplugin (which obtains the data from an Oracle DB via a perl script.

My question, is would MVC apply in this circumstance, and would anybody have any good advice/resources on how I can now, post-design to implement it?

Thanks.

The MVP pattern is more adapted to WinForms applications. Here's a nice article you may take a look at.

Received wisdom is that MVC is good for the web but has some constraints when operating in a desktop environment (I'm not sufficiently experienced in applying this sort of pattern in either context to make a worthwhile judgement).

The pattern that Microsoft (for one) are pushing for forms use is MVVM - which is Model View View Model - and it provides a similar set of benefits in terms of separation and testability. Even allowing that I could wish I knew more I can see what and why, especially if you're looking at WPF (and Silverlight) but in any context where you're trying to ensure separation.

The MVC pattern can work well with WinForms, see this question .

There are lot of related pattern to choose from; in the case of WinForms (unlike WPF) there is no clear winner.

Partly this is due to everyone having different aims, do you care most about:

  • Code reuse between Forms in the UI
  • Being able to support form the one UI system
  • Easy unit testing
  • Etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM