15
Jul
06

In Search of Windows Forms Patterns


I have done a limited amount of Windows Forms development, especially when compared to ASP.NET. I don’t feel like I have ever truly done it right, there has always been an uncomfortable amount of duplicate code and way too much crap in the UI.

I am working on a side project that uses Windows Forms and I want to do it right, but I have been having a hard time finding good guidance on how to best architect a Windows Forms presentation layer.

Most of the Windows Forms books I have browsed through focus almost completely on the technology details (how to databind, how to show a dialog, etc), not how to best implement it. Patterns and Practices has some decent guidance in this area, but I keep hoping to find something more comprehensive. (This would be a great book opportunity for someone)

Here are some of the things I have found useful so far:

Any Windows Forms developers want to chime in with some other good resources?

 



Comments

7 Responses to “In Search of Windows Forms Patterns“


  1. #1 Omer van Kloeten 7.15.2006 at 9:51 PM

    I'd forget about using UIPAB for Windows Forms development if I were you. It's too buggy and lacking to use in Windows Forms as it was created for Web Forms applications.
    I think Model View Presenter is best if you have an object model behind your views.

    But what really matters is sticking to the pattern, because if you cut corners, it gonna get unmaintainable. My project has some lazy developers who develop 'outside' the pattern because abiding to the pattern is 'inconvenient' and the code base has simply become unmaitainable as a code base that uses the UIPAB.

  2. #2 Kris 7.16.2006 at 5:21 AM

    I'd recommend also checking out Fowler's Presentation Model pattern as well. After trying a few implementations using MVP, I found Presentation Model to be much easier while still providing reusability and forms that were dirt simple. For instance, it was easy to utilize the presentation model components in some automated FitNesse testing we had on top of our NUnit tests. Avoiding unnecessary interfaces for dialogs and forms was a nice thing IMO.

  3. #3 Tim 7.17.2006 at 7:49 AM

    This advise is not so much patterns oriented. I have developed for both Windows based forms and ASP.net forms and by far I have found ASP hardest because one must cover more presentation cases. But I don't think your problem is as specific as Windows Forms vs. ASP.net. I think it is an aesthetics issue. What presentation pattern works better as a desktop app vs as a web app. It might be helpfull to expand your search in those terms. Once you know what works on general aesthetic level I think the .net implementation should be much simpler.

  4. #4 Jason Kemp 7.19.2006 at 5:01 AM

    Wow!

    Thanks, James.

    I agree there isn't a lot of good info on architecting a Windows Forms GUI; what I've learned is through trial and error and paying attention to everything I can for some ideas I can use.
    I'm not sure there are that many WinForms shops out there right now. Whenever I'm around fellow .NET nerds, I'm often the only one who does Windows-only development. Then they start talking database access and HttpHandlers, and I stop listening :)
    We've made mistakes in our UI that are really painful and we're regretting them all the time. One of the downsides of choosing the Windows Forms route is that you HAVE to get it right the first time because deployment is so much harder.
    Charles Petzold had a post about Visual Studio rotting the mind a while ago; I think he's on to something. Many of the mistakes I see are a result of starting out with the Form in the designer and coding down, as opposed to starting at the data and business object level and coding up.
    I'm curious to know what you find in your hunt. :)

  5. #5 Kris 7.20.2006 at 5:43 PM

    Martin Fowler just updated his UI patterns, so there is definitely some good stuff here worth checking out.

    http://martinfowler.com/eaaDev/

  6. #6 Luke Melia 7.21.2006 at 3:44 AM

    Another vote for Presentation Model. Be strict. The *only* thing a view (e.g. a Form class) should do is update itself from the PresentationModel and handle user input by calling command-style methods on the PresentationModel. We test drive the PresentationModel and wiring up the UI is invariably a cinch...

    Have fun!

  7. #7 Yiyi Sun 7.21.2006 at 1:38 PM

    My two cents go to the Presentation Model too.

    I have refactored the CAB Smart Part Quick Start sample to MVP and PM and added unit tests. Souce code is ready for comparision at:
    http://yysun.wbeditor.com/?p=33