views:

36

answers:

1

Hi,

i'm about to create an app for my client. Multiple clients of him (of my client) will login to that app and do the same thing. So in that view, we have a 'generic app': written once, suits every clients needs.

But, before the first line of code is written, we have offcourse the first exception: when client A does action A, you have to do the same as for clients B, C and D, but also.....

And of course, we can wait for more of that kind of modifications of the first thought out 'one flow for all'.

No problem, can't foresee all, and source code is flexible.

But, i foresee my source code with all kinds of if statements:

if (client == "a")
{
  SetEndDate(+1);
}

else if (client == "b")
{
  SetEndDate(+10);
}
else //no enddate modification needed for other clients

if (client == "d" || client == "E" )
{
  DoExtraCheck1();
}
else if (client = "b")
{
  if ( DoExtraCheck1())
   {
       DoExtraCheck2();
   }
}
else //no checking needed for other clients

and i'm getting scared of that!

What could be a nice elegant solution to streamline this?


Next thing to solve is of course if the UI also changes between clients, but that is for the V2 question :)

+2  A: 

A good way to handle these things is the strategy pattern. You can implement a default strategy for all clients, and subclass it for clients that have special behavior. The ifs in your source code will be handled by polymorphism.

Extra processing (e.g. checking invariants or stuff like that) that does not change the interface can be implemented using the decorator pattern.

The difference between the two is that the decorator pattern is intended to extend functionality, where with the strategy pattern you can actually change the implementation.

Both of these solution assume that you can define one interface for all clients, and thus can exploit polymorphism.

Space_C0wb0y