Make your views stupid

April 11th, 2008

I’ve been working on a project that is using a Model-View-Presenter pattern. I’ve noticed something in the view code that I want to write a quick post about: views that are way smarter than they should be.

The presenter represents the workflow or process that the user is working on. It encapsulates the state of a use case instance. It has the responsibility of responding to the user’s interaction. The view simply displays data and sends messages back to the presenter when the user interacts with an element in the view.

If you have code like this in your view:

// some button click event handler
presenter.DoSomething();
presenter.RefreshTheView();

then you have a bad smell. It should look like this:

// some button click event handler
presenter.DoSomething();
// presenter’s code
public void DoSomething()
{
// build a request from the view data
// do something
// refresh the view
this.RefreshTheView();
}

Unless you have a lot of formatting to do in the view, your view should be comprised of a lot of one line method calls back to the presenter (or preferably raised events). The presenter should tell the view “show this to the user” and, optionally, “action XYZ is not available”. The view should tell the presenter “the user did something”. I like to specify this as events on the view interface so the complete communication contract is documented in one spot – but that’s another post.

We're back

April 11th, 2008

Hi, all. John and I took the blog down for a while since we weren’t doing much blogging at the time. We both despise SLBs – shitty little blogs – and ours was becoming one so we decided to take it down for a while. A lot has happened since then.

The short story is that John and I used to work at a company called Inetium . It was there that we started working on HumanStuff as a concept or hobby company. In December John and I made HumanStuff a reality. We are providing consulting services in the Twin Cities. We still have plans for developing products as well but that will be secondary to consulting.

It is currently just the two of us. However, hiring is in our plan so we’ll keep you posted. You can start preparing for the interview by reading the manifesto . I think the interview process will be sitting down and writing an application soup to nuts given a set of requirements (see “How to hire a juggler” in Peopleware ).

I’ll be blogging about the experience of building the business, development, stuff we’re working on, etc. If you have tips on how to improve the blog please send me an e-mail at yourblogsucks (seriously – I have an address set up for that and am looking for feedback) at humanstuff dot com.

Cheers, Dan