Search This Blog

Loading...

Monday, May 12, 2008

Why WPF is Great

Josh Smith has an interesting article on WPF. In that article he discussed the shortcoming in WPF ( no RAD editor in Windows Forms or ASP.NET sense and the need to master XAML), and offered a few reasons why despite this, people are still rushing to WPF. Some reasons mentioned include:
  1. The ease to create 3D animation
  2. The data binding system
  3. The separation of presentation and the logic
  4. Get a jumpstart on Silverlight, which is a subset of WPF.
  5. WPF is more aesthetically pleasing
I think that WPF is great for this single reason:

It's possible to test the UI logic

Yup, this one single reason is more than enough to say that WPF is great.

Windows Forms, or ASP.NET Forms feature a great design time compiler. But they suffer from a significant problem: they make unit testing hard. The presentation layer and UI logic are hopelessly cluttered together. For prototypes this may not be so much of a problem. But for big scale projects this is a very significant drawback as unit testing is the bedrock of software quality. In such a situation, the standard advice is to keep the presentation layer as thin as possible. But the current Windows Forms design just won't encourage that.

Things have changed in WPF.

In WPF applications, all markup is stored separately in the xaml file, so there is no confusion between the presentation objects and the logic behind it.

What about event handling, data changes and the stuff?

WPF takes care of it by allowing you to bind the data directly to an UI object. You can write the appropriate conversion or logic in a separate class. So when you need to test whether your UI logic, you just have to test the conversion class. There is no need to simulate mouse clicking or text entering event in order to test your applications. You just need to test the appropriate action classes, using all the standard testing facilities you have.

WPF makes TDD possible for UI layer. This is why it is great.


4 comments:

Josh Smith said...

Excellent point!

lbugnion said...

Hi,

Totally. Using a MVVM (or similar) patter to define the UI's behaviour has a lot of advantages, not the least being the ability to unit test the UI.

Check an article I wrote last year about this:
http://www.galasoft.ch/mydotnet/articles/article-2007091401.html

I also have a "best practices" application as part of a presentation I am currently running. It uses the MVVM pattern to define data, and to provide a test mode to the application. You can load it here:
http://www.galasoft.ch/presentations_en.html#SiemensGoesWPF

Greetings,
Laurent

Soon Hui said...

Thanks, Josh

Soon Hui said...

Hi Ibugnion,

your post seems like an interesting one, will definitely have a look :)