Utah DNUG :: UI Design Patterns

Posted Thursday, November 13, 2008 7:21 PM by Nathan Zaugg

Presenter: Joe McBride

Date: Thursday November 13, 2008

Place: Neumont University


I am pretty excited about this.  I am a big fan of design patterns and the presentation promises to cover MVC and MVP design patterns and those are not well understood architectures and I was also interested to see how it was applied to WPF.  There is also an additional pattern described called "Model View ViewModel"(MVVM).

Model View Controller (MVC)

This model seemed to be presented a bit differently than I expected.  The slide suggested that the Model could somehow be used circumventing the presenter.  Regardless, the MVC was described much like an API that is available for the view to consume passing nicely typed domain objects back and forth. This is a pretty straight-forward design pattern and has a lot on common with nTier. 

One of the good things about MVC is that it is much easier to test.

Model View Presenter (MVP)

The view can raise events to the presenter and everything is marshaled through the presenter.  One of the pro's about MVP over MVC is that data binding is made possible. The presenter becomes the gateway for any logic -- the object you are using to bind with doesn't need to be a domain object but can be a UI object. Data binding is the coolest and least understood part of WPF and I believe that Data binding could have been applied with the MVC pattern but the MVP is clearly easier.  The binding statements were very simple and the code looked pretty clean. 

One thing that I might not like about MVP is that the objects returned may be too customized for a particular view and if you plan to deploy this code with multiple views, for WPF and ASP.NET for example, may need entirely different types of objects for data binding.

Command Pattern

The command pattern is a lot like a fire alarm.  When there is a fire someone pulls the fire alarm and everyone exits the building.  In this analogy the fire alarm is the "command", it is invoked by someone pulling it and anyone could pull it.  When it is pulled everyone interested in the fire alarm takes appropriate action.  This is actually an analogy I came up with on the fly but I think it's a great way to describe a pretty abstract concept. 

Model View ViewModel (MVVM)

This is a new pattern to me -- I have never even heard of it before.  I do think that this approach could have some advantages where the ViewModel could be customized to work better with the actual view.  This is also a good place to implement the command pattern.  It is also a very useful that commands can be disabled which makes will actually update the WPF UI! That is pretty awesome!  The only potential downside (if you choose to call it that) is that there seems to be mode code involved even if it is somewhat abstracted away from the UI. 


Part of a good measure for any presentation design pattern is how testable it is.  I really believe that if you can keep your UI code to a bare minimum that the unit tests will be substantially more effective. 


  • I like the microphone. 
  • Great turnout.  I counted about 45 people in attendance
  • It's very un-impressive when in the first 30 seconds of the presentation the code is broken; it was fixed very quickly though.
  • Too much on a single slide.  Could have done well to split them out into two or three slides.
  • Pizza was gone by the time I got there....bummer!  Probably makes my review more critical -- I need Pizza!
  • I think it could have been possible to do this almost entirely via Commands which would eliminate any code required on the code-behind for the view.  That might be an interesting thing for me to try later.
  • I was shocked when Charles Petzold's book was not mentioned as a good WPF resource!  Geesh!  Also, I don't believe Adam Nathan's book (WPF Unleashed) is difficult and fast-paced.  I actually found it a quite addicting read.  Maybe not so much for the writing style (Petzold is clearly the literary master of the two) but because WPF is just such an interesting subject.
  • I couldn't believe how few people know what the Command Pattern is.
  • I would like to have seen more interfaces and loose cohesiveness.  Okay -- Nevermind!  Just as I typed this he showed that he was using an interface.
  • I was very disappointed to see the use of var where objects are not anonymously typed. 
  • The presentation didn't seem to flow too well at times.  I was also hoping to see a bit more of the mock objects and how to create those for unit testing.


Thanks Joe! Great presentation.  Very good demonstration code used and it was very simple and small.  I have to admit I am a little jealous of your blog domain and I think it's cool that he got it and that he actually uses it.  Hopefully we can link to each other more in the future.




# re: Utah DNUG :: UI Design Patterns

Thursday, November 13, 2008 10:22 PM by Joe

Hey Nate, thanks for coming and thanks for the tips!  As per Petzold's book, I haven't read it so I can't really knock it either way.  I am, however, a very visual learner so I haven't read it solely on the fact it has no pictures.  Now that I'm well versed in WPF it may be worth another look (it is Petzold we're talking about).

I agree on the mock objects ... I think Unit testing and mock objects could be an entire presentation itself.