Archive for January, 2007

This is something that comes across the CAB message boards frequently. People who are new to the Component UI Application Block look at the way MVP is implemented in the reference implementations, and one of their first observations is: “But it’s not loosely coupled!”

My response: That’s not the reason to be doing MVP.

This is just my own observation, but I think there’s a general misunderstanding at times when it comes to Model-View-Presenter. Some people think it exists to promote “loosely coupled” code, but that’s not really the case. That’s not really why we do MVP.

Model-View-Presenter
, and it’s cousin Model-View-Controller, exist for two very important reasons, and neither one of them has anything to do with loose coupling. Oh, don’t get me wrong: loose coupling in an object-oriented application is generally a good thing. With loose coupling we can be more agile in our development process; we can enact change at the customer’s request without breaking other systems, and that’s good for flexibility. That’s good design.

But loose coupling isn’t why we do MVP. We do MVP for two reasons: (1) Clear separation of concerns which leads to (2) easier testability.

If you think about it, it all makes perfect sense. What is a view without a presenter? What is a presenter without a view? These objects are the perfect example of a symbiotic relationship. One cannot really exist without the other (well they can, but then they’d be useless). A view is just dumb user interface code without a presenter to manipulate it. A presenter is just useless business and application logic without a view to display it to the user. And both of these objects need to know about the other in some way, because they’re going to be dealing with specific business data. Would it make any sense to attach the presenter for Ice Cream Inventory Management to the view for Oil Change Orders?

There was a time, not so long ago, when these two objects were one. We simply referred to them as a “Windows Form” or a “Web Page.” The UI code was intermingled with the application logic and business logic, and what you ended up with was a big mess of code that wasn’t easy to change and even more difficult (if not impossible) to test.

Then came MVC and MVP. Granted, these two patterns have been around since SmallTalk, and maybe in the SmallTalk world they existed to promote loose coupling. But if that was the case then, it’s not the case now.

The biggest advantage to MVP is testability. Presenters reference a view via its interface, and that’s the key to making mocks happen – to removing the real view from the testing equation. We wouldn’t need to perform this step if we simply wanted to have a clear separation of concerns; if that was the case we could just use concrete views, and as long as the view and presenter code were separated we’d be keeping a clean house. But with an interface we enable automated testing; we enable the view to be replaced with a mock object that implements the same interface. With a properly mocked view we are now free to test the presenter’s logic with a test framework like NUnit. And that’s the real goal here: testability. Testing gives us, and the customer, confidence in the code. It gives developers confidence to refactor. And that makes the MVP pattern worth its weight in gold.

What’s not to be overlooked in all of this is the separation of concerns. It’s not the same thing as loose coupling, but it is no less beneficial to a large application. Programming a large business application can require many pieces of a large puzzle. Code should be easy to navigate and refactor. Determining when and where to make changes to a system should be something that is painless and easy. Developers shouldn’t have to hunt down the location of code; they shouldn’t have to dig through large classes and intermingled logic to find the relevent lines of code they need so they can make a change. They should know, almost intuitively, where to go to find code related to the User Interface, or code related to the application logic. Separating our code and giving objects clear responsibilities makes development easier, and it makes our code better. A presenter and a view are, after all, objects. They should adhere to our basic object oriented rules on encapsulation and responsibilities.

Clear separation of concerns is just good object oriented practice. Think of objects like vendors at a football stadium. They each have their own section of the stadium that they are responsible for. The peanut vendor in section A3 shouldn’t also be responsible for selling hot dogs in section F6. Our view shouldn’t be handling business logic or application logic; it should just be handling view logic. In the long run, this makes for an easier system to develop and an easier system to maintain.

Sure, there’s a bonus to all of this: you could potentially swap one view for another using the same presenter, as long as both of those views implement the same interface. And you could do the opposite as well, if you really want to expend the effort, and make your presenter implement an interface. Then you could swap presenters on the same view. But those capabilities are a side-effect of MVP, not the reason for doing it. It’s like skipping through commercials on TiVo. It’s a neat thing to be able to do, but the real reason to own a DVR is so you can record television shows that you can’t find time to watch in real time.

In practice, swapping views/presenters doesn’t happen very often outside of testing (and just as I say “not very often” five people will raise their hand and say, “but we do it all the time!” And you would be the folks who make the “not very often” statement reality, instead of it being “never”). And it shouldn’t happen very often unless there’s some darn good business reason to do so. And if there is some darn good business reason for frequently swapping views/presenters, then you probably need more than MVP. You need a truly pluggable component model architecture. For most of us who are building business applications with a lot of specific business logic that needs testing, that’s not what we really need to do. What we’re after is providing customers with business value. Getting data to the screen in a format the customer can understand and make use of, and ensuring the quality of the code through rigorous testing.

That’s why we do MVP.

So when you see MVP in CAB and realize it’s not loosely coupled, don’t freak out. Those two objects – the view and the presenter – would normally be one object. But they’re separated for very good reasons, and it’s not for the exclusive purpose of promoting loose coupling.

There’s a method to the madness.

DotNetFramework 3.0

Yesterday we stumbled on a nifty little problem: how to select .NET 3.0 as a prerequisite for a ClickOnce deployment. When we went to publish our app, which uses WCF and thus requires version 3 of the .NET Framework, we found that .NET 3.0 was not a selectable option in the prerequisites dialog. We could only find a checkbox for .NET 2.0.

After some research, we found various blog posts that said you need to copy the .NET redistributables to a subdirectory under your Visual Studio location. Unfortunately, just copying the files is not enough.

What you really need to do is download vsextwfx.msi, the Visual Studio 2005 extensions for .NET Framework 3.0 (WCF & WPF), November 2006 CTP. These extensions will enable the .NET 3.0 Framework as a selectable option in the prerequisites dialog in a ClickOnce deployment.

One other caveat: If you’re like us, you probably want to put the .NET Framework redistributable files on a local fileserver, instead of choosing the “Download prerequisites from the component vendor’s web site” option (at least if you’re application is like ours and only needs to be installed on a local intranet, not available to the world at large).

Installing .NET 3.0 over a network is a bit faster than the web. However, after you’ve pointed the prerequisites dialog to some file share on your network, like “\\ourserver\DotNetFramework”, you’ll notice upon attempting to install your application via ClickOnce that it complains it cannot find the .NET 3.0 Framework files, and it is looking in “\\ourserver\DotNetFramework\NETFX30″. For whatever reason, the NETFX30 gets appended to the location you provide in the dialog. So when you create your directory, make sure you also create a subdirectory for NETFX30 and that is where your redistributables should for .NET 3.0 should go.

Happy deployment!

Bears 27, Seahawks 24

That’s what the final score reads. And for most of the east-coast (biased) media, that’s all that matters. A win is a win, a loss is a loss, and they prefer to see things in simplistic black and white. It wouldn’t matter if Seattle lost by 30 or 3; the media had declared Chicago the winners of this game before it even started, to the point where Fox announcer Joe Buck took a moment to take a shot at those experts right before kickoff with a line that went something like, “We have video evidence that the Seahawks have shown up to this game…”

But quip or not, the whole thing disappoints me.

Not so much the loss – of course the loss is devastating to us fans, we live and die by our teams, and I feel blue today because the Seahawks won’t be playing next week in the NFC championship game – but the media’s coverage of this team, both before and after the game, is really what draws my ire. And that horrid coverage continues today. I find myself feeling angry as I read through columns and articles of the sport’s most well-known reporters.

I’m disappointed at the sheer lack of respect that Seattle receives; the lack of acknowledgement. It’s disgusting. I’ve never seen anything like it in my short, 35-year lifespan. I’ve never seen the media so gleefully and obviously ignore a franchise that has rose from mediocrity to now make the playoffs five consecutive seasons. They were 11 yards away from Josh Brown being able to attempt a game-winning field goal. They were an overtime drive away from beating the Chicago Bears, a team that everyone in the US outsite of Seattle had already annointed as the winners, even before a snap took place. But to hear the media tell it the ‘Hawks lost by 30 and were never in this game.

Peter King, who may be the most obvious proof that east-coast bias exists, devoted the first 1,565 words of his Monday Morning Quarterback column to an essay on the New England Patriots - his favorite team – and how great they were as they beat the AFC’s #1 seed, the San Diego Chargers. Conversely, the only mention of the Seahawks in his column, after a thrilling overtime loss where they nearly stunned the Chicago Bears (in a game that wasn’t even supposed to be close, if you listen to the “experts”), is this paltry line:

10. Seattle (10-8). Anybody on the Seattle defense feel like covering Rashied Davis in overtime?

Fifteen words is what the Seahawks got in King’s column. The Office comedy from NBC got 19 words.

That is the state of Seahawks football. And it makes me mad.

It infurtiates me, because this team played with heart and determination. Peter King likes to extol the virtues of his New England Patriots and how they are the consummate “team.” But he can’t even take more than 15 words out of his column, or five minutes out of his busy schedule, to learn about the best “team” on the west coast. Ever since the Seahawks hired Tim Ruskell as their General Manager this franchise has been about character, heart, and determination – and all of that has helped them turn their fortunes from perennial losers to playoff winners. For 65 minutes on Sunday they gave the Bears everything they had, despite three of their top four cornerbacks being out to injury. Everyone knew the Seahawks defensive backfield was a patchwork unit, and still they managed to knock off the Cowboys last week and were an overtime win from doing the same to the Bears.

But what does Peter have to say about it? His only mention of the Seahawks on Monday morning is a quick rag on their depleted backfield. No praise for a patchwork unit playing with a guy who was a loan officer two weeks ago and had spent the entire regular season not in the NFL. No recognition for the guts that Shawn Alexander and Matt Hasselbeck showed after spending large portions of the season injured (Hasselbeck still playing with a fractured left hand). No recognition for the way this team had overcome major injury adversity to reach the playoffs, something that had not happened in the five previous seasons and for which fans and media alike had dubbed “The Playoff Loser Curse.” No mention of the coaching job Mike Holmgren did to get these guys ready to face the Bears on Chicago’s home turf. No mention of the job defensive coordinator Jim Marshall did despite a patchwork defensive backfield. No mention of the heart and toughness Seattle’s “undersized” defense showed in pressuring Rex Grossman. It took overtime for the Bears to win it. But you wouldn’t know it if you read Peter’s column. Hell, you would hardly know there was an NFC game on Sunday.

I wasn’t angry when the game was over. I was blue; I felt very sad for the guys on that team because I felt they deserved to be there and deserved to win. They are better than anyone in the media thinks the are. I thought it they could have won, what a great story it would make for the NFL post-season. To see this team rise out of the ashes of an injury plagued season to knock off the #1 seed at Soldier Field would have been amazing. What a story. An hour or two after the game, knowing how close they were to that sort of finish, I was back to normal. I was proud of this team, and proud to be a Seahawks fan.

But today I’m angry. Angry at the way the media treats this team. Peter King added insult to the loss with the way he refused to acknowledge this team. In his “Fine Fifteen” he ranks Seattle tenth; with the Dallas Cowboys (the team Seattle beat last weekend) and the New York Jets ranked ahead of them. And his beloved Patriots? Why, they’re #2 of course.

The Patriots had to do the same thing the Seahawks had to do Sunday to win; grind it out against a great defensive team. The Patriots won by three points. Seattle lost by three in overtime. But in King’s world, the difference between these two teams isn’t that close. It’s a canyon. A gulf so wide that he can devote 1,565 words to the Patriots on Monday morning, but only 15 words – one critical sentence – to the Seahawks.

Today, I’m proud to be a Seahawks fan. This team does things the right way. It’s easy to root for these guys. They show heart and guts and determination like few other teams in the NFL. Five straight years they’ve been in the playoffs. But this morning I learned that center Robbie Tobeck is retiring, and Pro Bowl fullback Mack Strong might do the same. And who knows how much longer Mike Holmgren wants to coach? I can’t think of another coach I’d rather have to coach this team, except maybe Sean Peyton, and he’s not going anywhere anytime soon.

I don’t think the window of opportunity is closing on Seattle’s Super Bowl aspirations – I think Ruskell will keep this team competitive the same way Bill Belichick and Scott Pioli have done it with the Patriots – but the view may be changing significantly. I only wish the national media were more aware of this team and their makeup. In a league that holds up teamwork and determination, heart and professionalism like standards in a Roman army, it’s shame to see the Seahawks – a team that embodies all of the best qualities of the NFL – so easily dismissed and ignored, despite their post-season appearances and amazing effort in the face of adversity.

It’s tough to see your team lose. But I would have rather they lost by three in overtime than get blown out like they did in week 3. They had a chance to win and almost did. They belonged. They deserved to be there. It’s just a shame that no one else sees that.

My resolutions are always boring. Lose weight. Exercise more. Practice my guitar with more regularity. No one wants to hear about that though, so I decided to use my blog space to help other folks write resolutions. Besides, these people need help.

Rosie O’Donnel: I resolve to stop being a fat pig. From now on, I’ll try and be a thin one.

Barry Bonds: I resolve to tell the truth about steroids. Just as soon as my nose quits growing.

Terrell Owens: I resolve to think about other people first. I resolve to admit that I am to blame for my own mistakes. I resolve to be part of the solution instead of part of the problem. I resolve to show respect to my teammates and fellow players. I resolve to… ah screw it. I hate all of you.

Michael Irving: I resolve to quit sucking up to T.O. I resolve to stop clutching my co-host’s arms on NFL Countdown. I resolve to think before I speak. I resolve to… ah screw it, I hate all of you too.

Britney Spears: I resolve to wear panties.

Paris Hilton: I don’t.

Dick Cheney: I resolve to check my target more carefully.

President Bush: I resolve to admit I made a mistake. Just as soon as I make one.