Feature Toggle (Part 1 of N)

Do you have a variable flag which depending of the configuration the flag will enable/disable (toggle) to execute some lines of code of a feature.? are you tired of this approach?

This patterns was known as “Feature Toggle” which is a set of patterns which can help a team to deliver new functionality to users rapidly but safely.

“Feature Toggling” could be done with t just a variable flag but there are other better way to do it but of course it will require more time to implement it.

Working with toggle feature it will help in:

  • Adopt new technologies as part of feature toggles
  • Clean Code (if don’t use just simple variable flags)
  • Reduce Risk branch merges issues “feature branch”
  • other more things!

overview-diagram.png

Image source from this great “Feature togglingarticle

“Feature Toggling” could be used when

your software need to use a feature that break backward compatibility and is only available in the latest version of a library . Instead to break the backward compatibility or don’t get the latest version of the library it could be modify the code to call that new feature only if the software has the latest version otherwise it won’t use this feature and it will execute other code. With this approach it will adopted fastest the latest libraries version instead to wait years to be possible to update you code.

From a software architecture point of view which solution and patterns do you use for the “Feature Toggling” ?

toggle-switch-variations_29-345

I think one possible solution it could be create some artefacts which will inject the desired code to be executed with a dependency injection library instead to have a simple flag with more code in the same location.
I think the correct approach is to try to have those new toggle feature code in a separated location but once release is complete toggles need to be removed.
Instead to reinvent the wheel bear in mind there are some existent library help with this and here below we have some example links

There could be some disadvantages like:

  • flags make the code more fragile if won’t be well designed
  • harder to test if it wasn’t well documented or created test,
  • harder to maintain if it wasn’t properly designed and there no test
  • What else?

Here we have a list of great articles about toggle feature:

Don’t try to don’t reinvent the wheel and use an existent C# libraries:

There are also Web development toggle feature libraries like:

  • Angular
  • React
  • Typescript

Feel free to share with me how do you archive this or to discuss about this topic

 

Tweets related with this topic:

 

Leave a Reply

Your email address will not be published. Required fields are marked *