I’ve previously stated that the MVP pattern could be advantages for XAML based applications. I haven’t provided WPF examples yet as I fear that these may compromise the design-ability of the XAML layout.
Florian Krusch describes the beginnings of an MVP style pattern for WPF (and Silverlight) applications in his article:
He states that the pattern described by Martin Fowler “Supervising Controller Pattern” (still under development at time of writing) may be relevant in this case. (The term Controller and Presenter are used interchangeably in Fowler’s article)
This pattern has been created in order to facilitate frameworks such as WPF that have a data binding capability. I understand however that it expects one-way data binding (read) with the view look at the model directly. Updates to fields are delegated to the controller, which in turn updates the model. This sortve neuters the 2-way data binding in WPF.
The true objective of these architectures is testability, with the assumption of the view being difficult to work with in the unit test environment.
An architecture that may work is something like the diagram below:
In this proposal both the View and Model could be mocked successfully.
In future posts I’ll endeavour to create some code to show how this may work in the real world.
Using the Supervising Controller doesn’t rule out standard 2-way data binding. Letting the View itself handle synchronizing the Model with the View is really the point of Supervising Controller as opposed to the Passive View flavor of MVP. All the controller is doing is handling the more advanced behavior and workflow with the rest of the application.
That is so ridiculously complicated and stupid. It’s a testament to the fact that ULTIMATELY you didn’t end up posting “code to show how this may work in the real world.”
It doesn’t work in the real world. I read Martin’s articles, and I am not afraid to say I didn’t understand his patterns happy terminology. It seems Martin doesn’t understand the underlying principles behind GUI architecture, and he is making up patterns to cover up this fact. He’s a brilliant man, and this brilliance is getting him and his readership in trouble.
Hi John,
Thanks for the point of view. I felt the same way about this kind of pattern in the past, as unnecessarily complicated. Once you get into it though you can see it can be implemented simply. The primary advantage for me is being able to create powerful automated unit tests that run realy fast.
I didn’t follow up this article with code because the Microsoft Patterns and Practices team have released some guidance and code in this regard already with their “Composite Application Framework for WPF”. There’s also another project called “Calliburn” which I’ve heard good things about.
http://www.codeplex.com/CompositeWPF
http://caliburn.tigris.org/
(Although these are interesting, it’s pretty easy to do these architectures without using a framework and still get the benefits)
Subsequent to this article I have created MVP style applications for VSTO, Winforms and WPF. All of these have benefited from test coverage that would in some cases be impossible to achive in any other way. (Try configuring Outlook on a build server…)
Thanks for the comment.
Regards
Julian