Question

As a vendor, we need to ship applications to many clients, and sometimes we need to customize the application for a specific client, for example by enabling or disabling certain features, or setting appropriate defaults for that client.

I've seen that in some open-source projects this is done with this pattern:

#define ENABLE_FEATURE_XYZ 0

#if ENABLE_FEATURE_XYZ
void featureXyzImpl()
{
    ...
}
#endif

void main()
{
#if ENABLE_FEATURE_XYZ
    featureXyzImpl();
#endif
}

Here you turn the feature on or off by defining ENABLE_FEATURE_XYZ to 0 or 1. The benefit is that code that is not needed is not there.

But some colleagues believe that in the real-world, you need to perform customization at run-time by looking at config-file or registry settings, using this pattern instead:

void featureXyzImpl()
{
    ...
}

void main()
{
    if (configFileValue("Enable Feature XYZ") == true) {
        featureXyzImpl();
    }
}

Their reasoning is that it makes it easier to maintain and test the software, because you don't need recompile to enable or disable a feature, you don't need to keep multiple versions of a library or an executable, and you can send only one version to the testers, who can then enable or disable features at run-time.

Is there a guide, or methodology for deciding which one of those methods is better for a given situation? Or should we just choose between them with a coin toss, or out of personal preference?

Was it helpful?

Solution

I think it depends on how much "sometimes" is. If you enable/disable features by building an individual version for each customer then you carefully need to keep track what you have delivered to what customer since you need to support there special version of the application. When using configuration files the clever customer may have the chance to enable features he did not pay for but maintenance is much easier for you. I would stay with configuration files as long as possible since they are much easier to maintain.

OTHER TIPS

If you individually compile your application for each customers system, I would say you can do it as "conditional compilation". Also you should do this if you have some customer groups, and you don't want that anyone could "hack" your program to abuse features he isn't paying for. But in any other case I could imagine there would it also be the better solution to disable it on runtime.

EDIT:

According to your run-time example: This is the only option you have, if you were a 3rd party provider, where the customer had to turn on and of features by himself, and you are just bring onto account what his customers have used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top