Friday, 29 December 2006

The "message bound" command pattern

How can a server dynamically handle all incoming requests without performance drawback ?

I'd been searching for a satisfactory solution to that problematic since a long time... After I recently found one, I decided to document it as a Pattern:

The "message bound" Command pattern
"A controller that dynamically handles all incoming requests without performance drawback."

Reflection is useful and more elegant than static conditional logic to decide which command a server Front Controller should run from a given message/request.

Compares to the static implementation, reflection significantly improves the productivity of the development each time we need to add a new kind of message or request type to handle.

However, this elegance has a cost named performance… The "message bound" command pattern purpose is to solve this performance drawback.

Make it simple !

Contrary to appearances, the simplicity is difficult to obtain. When we develop systems, we tend to complexifier with excess. Then, the cost of the complexity of a system is directly tangible: difficulties to enter the code for every newcomer, painful sessions of debugage, bigger slowness for modification, etc.

Of course, pair programming and refactoring sessions can help us to aim towards this indispensable simplicity: It still have to be part of our objectives!

This is why I recommend you the post of Brad Abrams: "New Job Title: Senior Simplicity Engineer", and also the classical but always so relevant "The Parable of the Two Programmers".