Wednesday, February 11, 2009

C# MVP For You and Me - Part 2 - Jeremy D. Miller Leads Me Out of the Wilderness

Patterns are necessary for any maintainable, testable, well-architected GUI. This is especially true for a C# WinForms GUI, for all the reasons discussed in the previous series post.

Even Microsoft itself realized this and has, over the years, promoted a succession of pattern sets for .NET GUIs. These include the Composite UI Application Block (CAB), the Smart Client Software Factory, something called Acropolis, and finally something else called Prism. All but Prism appear defunct, and Prism seems geared primarily toward WPF, which I am not using (see previous series post.) More importantly, all including Prism are tremendously complex. Each one is a skill set in itself, like learning a whole new language. They're better than the Visual Studio approach of automatically generating two-tiered client/server apps, but are overkill for small projects like mine.

The .NET developer Jeremy D. Miller would agree with me. He wrote a series of blog posts, Build Your Own CAB, that describe a light-weight methodology for architecting C# WinForms GUIs. This methodology has enough structure to alleviate the dangers and shortcomings of the VS code generation approach, but is not so complex that people write books, teach training courses, and hold conventions to discuss it.

Miller's methodology is based on the Model-View-Presenter (MVP) pattern. MVP is kind of like the classic Model-View-Controller (MVC) pattern. The differences are so subtle that I will avoid discussing them. If you like, you can read about them here.

Once I finished reading the Build Your Own CAB series, I built the first screens of my app in a matter of days, and had an architecture that continues to carry me forward today. The screens more than met the standards I had set for myself. The code was testable, maintainable, and readable. There was not a line of business logic or service layer access in the actual GUI code. Miller helped me reach my main goal - that a brand new team member could read my code and understand it within minutes.

What I will describe in the next post is partly a summary of Miller's approach, and partly a description of how I implemented it. I have made additions and changes to his methodology, and I will state clearly where I've done so. No matter what you get from my reports, I strongly encourage you to read Jeremy's entire series. It has become my bible of .NET GUI development. Jeremy is a very smart and practical software engineer. I wrote my project based on his work, and will continue to do so until I switch to WPF. Once again, the link to his excellent series is here.

No comments:

Post a Comment