views:

40

answers:

3

How, in your opinion, should we code to handle enabling or disabling features based on the installation type. Purpose is to have a single installation for separate editions and make features available based on the installation type.

One way of doing it is to conditionally compile the code but that makes the code dirty and difficult to maintain.

+3  A: 

You can resort to plugin-based architecture, where all (or most) features are implemented as plugins that extend core app functionality. This way, your editions will differ only in what assemblies get installed/shipped/etc.

Granted, with this approach you can always make a "Starter" edition to turn into "Professional" by just copying missing assemblies. To solve this, you'll still have to resort to conditional compilation, but you'll have to conditionally compile blocks which are responsible for loading those plugins.

For example, suppose for your Professional edition you want to be able to add, say, export functionality. To that end, you create a separate IExporter plugin interface. Here's how you handle this:

public IExporter GetExporter(FormatType format)
{
#if PROFESSIONAL_EDITION
    return ExporterRegistry.GetExporter(format);
#else
    return NullExporter();
#endif        
}   

Thus, your Professional edition will have an ability to be extended with custom IExporters, whereas non-Professional editions, even with all "Professional" assemblies in place, won't be able to make use of this functionality.

Anton Gogolev
A: 

Flags would be one option, but I guess that would be 'conditional compiling'. Installation type would set a flag, based on the flags, some code would executed otherwise it would be ignored.

Can you have different branches of the code? That way each version would only have the relevant code for that install type. No need to carry around code that will never be used.

DaveWeber
"Branches" will make it difficult to maintain as the number of editions increase.
Faisal
+2  A: 

You can use conditional compilation or ConditionalAttribute. Here is an article explaining these topics: Building and Maintaining Multiple Application Editions using Conditional Compilation

Giorgi