Thursday, 11 June 2009

Simpletons - Smarter than you think

"Divide and Conquer" and "separation of concerns" are terms that have been banded around software design conversations for some time, yet how many of us still see classes being implemented that try to deal with everything under the sun? This got me thinking about how can we make it easier to visualize the simple entities, which are easier to understand and easier to test.

SimpletonAn object that has one purpose.

I applied this thinking to a recent story where I had to implement a security model in our public service api. The model needed to validate http requests against username and password and a digital signature.
Following the simpleton approach it was possible to drive out the following objects:


BasicRequest – Extract http BASIC credentials from an http request.
SignedRequest – Extract custom http headers from an http request.
BasicRequestValidator – Validate request based upon the provided basic header details.
SignedRequestValidator – Validates request based upon the provided digital signature.


By allowing objects to have only one purpose it was remarkably easy to tdd each object in turn and integration into the service tier was simply a case of newing up the Request objects and passing them to the validators.

So next time you're thinking about the objects you need in your system, become a simpleton, it might be pretty smart :-)