[Journal - Abstracting Client Specifics]

Abstracting Client Specifics

Friday, September 24, 2004

Suppose you need to implement a custom solution for some client that deviates from the standard behaviour of your application. The code goes like this:

if(Environment.IsClient("FatCorp")){
    // ...
}

If there is a second place where the code needs adjustment, well:

if(Environment.IsClient("FatCorp")){
    // ...
}

The trouble is, this kind of thing violates the SPOT (Single Point Of Truth) rule. If Fat Corp changes its mind about the "special thing", you need to change - oh, forgot: how many lines of code? Let's find out:

% grep IsClient * | grep -i fat
DataUtil.cs: if(Environment.IsClient("FatCorp")){
Contract.cs:   if(Environment.IsClient("FatCorp")){
ContractView.cs: if(Environment.IsClient("FatCorp")){
%

Too bad there is another special case, but we have to examine the code very carefully to find out whether or not it is related to the original feature request.

The solution is to abstract the rule away from the fact that it was Fat Corp who requested the change. So create a new property which say "implement the feature like this (or not)", and encapsulates the rule. Better yet, make it runtime-configurable.

Of course, we can still spend more time thinking about the right solution.