Implementing Variability

How not to do it

Clone-and-own. Ad-hoc refactoring.

Preprocessor directives

  • 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)

Parameterization

Frame-like techniques

  • No idea what these are about…

Object-oriented techniques

“Object-oriented programming is a major enabled technology… …encapsulation is a prerequisite for realising managed variability.” — Pohl2005, p.16

  • Delegation
  • Inheritance
  • Design patterns
  • Frameworks

Libraries

Configuration


Misc

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.


References


To the index!