How not to do it
Clone-and-own. Ad-hoc refactoring.
- File inclusion, macro substitution or conditional compilation.
- A bit messy, you could end up with directives all over the place if a feature spans lots of different bits of code.
- “preprocessor directives are truly usable only in the higher levels of architecture abstraction. In other words, “flags” should be used in a larger scope than single lines of code or even functions and classes, only to keep the granularity big enough to be manageable.” — (Tirila2002)
- No idea what these are about…
“Object-oriented programming is a major enabled technology… …encapsulation is a prerequisite for realising managed variability.” — Pohl2005, p.16
- Design patterns
In his article on feature toggles, Martin Fowler discusses some implementation techniques that could also be applied to implementing variability. (In fact, you could potentially think of feature toggles as variability in time rather than space…) For simple UI variability, he just has conditional toggles based on a config setting. For variability in application logic, he again suggests conditionals for a simple approach, or something more sophisticated like Strategy patterns and dependency injection.
- Pohl2005. Software Product Line Engineering: Foundations, Principles, and Techniques.
- Tiriala2002. Variability enabling techniques for software product lines.