1

I am developing an application where part of the supported features may become optional in the future, so the user can enable/disable them. However I am not aware of an approach in handling such optional features in the code.

Is it just like putting checks to see if the feature is enabled by the user or not, before executing that part of the code,

if (isFeatureXEnabled)  
{  
     //do something  
}    
else  
{  
    //don't do it OR show some notification/dialog to the user that it is disabled  
}

or (hopefully) there is a better approach/design pattern that can be used?

dragi
  • 129

1 Answers1

8

There are several approaches to this:

  • For simple and well isolated features, the simple flag could be a good approach.
  • For more complex optional processing, you could consider the strategy design pattern: this is ideally suited for alternative approaches in a general algorithm. "with" and "without" the option would be two different strategies.
  • in some cases, the use of a template method pattern could be a viable behaviour.

Finally, given your specific need, I'd strongly advise having a look at Martin Fowler's "feature toggle".

Laiv
  • 14,990
Christophe
  • 81,699