Thursday, June 21, 2007

The same but different

Allegedly Martin Fowler is working for some time on a second volume of Patterns of Enterprise Application Architecture.

One group of patterns he is writing about is Presentation Patterns. Here you can find the usual suspects like:

  • Model-View-Controller (MVC)
  • Model-View-Presenter (MVP)
  • Presentation Model

Its my experience that when you read the according papers for the first time, all those 'different but still similar' patterns can get quite confusing...

A co-worker of me once said that this is like the different revolutionary groups in Life of Brian:

Front

  • The Judean People's Front
  • The People's Front of Judea
  • The Popular Front of Judea

They all look the same, they all have the same purpose, sometimes they are even the same people ... but the difference is still more important than everything else!

Jeremy Miller now has set out to get rid of the confusion for good. He is writing a very instructive series of blog posts:

  1. Preamble
  2. The Humble Dialog Box
  3. Supervising Controller
  4. Passive View
  5. Presentation Model
  6. View to Presenter Communication
  7. Answering some questions
  8. What's the Model?
  9. Assigning Responsibilities in a Model View Presenter Architecture

The series is still ongoing, but I got already a lot of insights. If Jeremy continues like this, Martin is going to have a hard time to sell his book...

The post "What's the Model?" was especially interesting for me. I have already had tons of discussions about the pros and cons of using the Domain Model in the UI. Jeremy now lists objectively the different options, and shows that there is not one best solution. So this is an inherent problem, and its not me and my insufficient level of enlightenment...

Wednesday, June 20, 2007

Join Tables and Domain Models

In Domain Models arises often a design problem, when there is a relation between two entities and the relation itself holds additional attributes.

As an example a relational model would basically look like this:

Erd

Readings is basically a Join Table between articles and users, but it has additional columns on top of the two obligatory foreign keys.
When designing the associated object-model we are basically forced to create an entity for the reading, since there is no construct for ‘associations with attributes’ in current OO-Languages. But this often leaves a tainted feeling, because readings does not feel like a first-class entity in our model. Often we just want to navigate from articles to users, and for this scenario the reading should be transparent.

ActiveRecord in Ruby offers an interesting construct for this situation:

class Article < ActiveRecord::Base
  has_many :readings
  has_many :users, :through => :readings
end

This allows direct navigation from an Article-Entity to its User-Entities like this:

article.users.each do |reader|
  puts reader.name
end


Now I was thinking of an elegant way to do something similar in C#, when the yield keyword came to mind:

public class Article
{
   private readonly List<Reading> readings = new List<Reading>();
   public void AddReading(User user, DateTime readTime, int rating)
   {
      readings.Add(new Reading(user, readTime, rating));
   }
   public IEnumerable<User> Readers
  {
    get
    {
       foreach (Reading reading in readings)
           yield return reading.Reader;
     }
  }
}

The client code then looks like this:

foreach (User reader in article.Readers)

{

  Debug.WriteLine(reader.Name);

}

Ok, thats just the object model, mapping the whole thing to the database is another topic of its own …

Sunday, June 17, 2007

Hit the Nail on the Head

Life is entirely too short to spend human being time on writing ADO.Net code by hand in the majority of systems.  That's like sending people out to do the harvest with scythes.

Jeremy Miller

Monday, June 11, 2007

Heading for Madness - Part 1: Paranoia

How fast can you suck up new knowledge? How fast can you wrap your head around new technology? Where is your limit before your head explodes? How many choices can you handle?

When we started a new project 3 years ago, there was just plain WinForms. We started working and built up our UI-infrastructure/framework while trying to focus on the business-problems.

PromQueen1All the time I kept watching the technological front. I wanted to stay up to date, I wanted to put a foot into every bandwagon. But the parties on all those bandwagons made my head spin. On every party I met a new prom-queen, they were all extraordinary girls with exquisite names:

Every one of those new acquaintances assured me that her predecessor was quite a beauty, but nothing compared to herself. Every time I was falling in love and every time I was convinced, that this time its going work out fine between us. And I believed it with my whole heart … until the next party. It was always the same. I had learned all her methods by heart, I dreamed of her fine variables, I fancied her excellent features. I was prepared, I had pictured all her configurations, I had imagined all about her plugin-options, I really could not wait to get my hands onto her… and she didn't show up!

Each time my heart was broken and I was devastated. Fortunately my disappointment had not to last for long, since there was always the new prom-queen waiting for me. And always she was even more attractive and her promises were even more exciting!

PromQueen2But after some time I had enough. All this emotional involvement, and all for nothing. I took a break and reflected my situation. I came to the conclusion that I had to change my social environment: All those glamorous superficial UI-Girls, they are just not my type. It would never have worked out anyways…

So I started looking for another scene that would suit me better. I soon felt attracted to the simple and hard-laboring people of the data-layer. They were honest and welcomed me with open arms. And the girls were really nice, a bit naive but without any binding. They cared more for inner values and were far less focussed on their appearance than the UI-Girls.

So I drew new hope, and finally found the courage to go out with some special Data-Girls:

But it was the same all over again: Always on the second date a new girl showed up, one that seemed to be cleverer and more eloquent and have quicker wits than the one before. I got more and more confused to a point where I was completely paralyzed and could not decide which girl I liked most!

ParanoiaHonestly, can anybody be expected to keep up with this? How fast can people fall in love? How is it possible to build up a sustainable relationship, if the average lifespan is less than a year?

Is this some kind of evil conspiracy against me? Some emotional stress test? What will be the result? Survival of the fittest? Decision-inability due to choice–overload? Analysis Paralysis? Misantrophy?

I think I can never again speak to a girl without looking over my shoulder, looking for the arrival of the next, even more attractive girl. How did I deserve this? All I wanted, was staying up to date!

Related Posts Plugin for WordPress, Blogger...