The company that I work for has gone off the deep end with feature toggles-configuration keys that turn on/off particular behavior based on certain conditions. Martin Fowler actually refers to them as business toggles (http://martinfowler.com/bliki/FeatureToggle.html).
We have many clients all using the same service, but each wants slightly different behavior. Even worse, many want certain subgroups of their users to see different behavior. Thus, we use business toggles. The toggles have become a spaghetti ball of if/else logic that with occasionally unexpected interactions.
Are there any design patterns useful in managing a situation such as this?
Cheers!
Use the Feature Toggle pattern when Giving different features to different users. Rolling out a new feature incrementally. Switching between development and production environments. Credits Martin Fowler 29 October 2010 (2010-10-29). Designed by markusmo3⋅ © 2014-2021 Ilkka Seppälä
Feature Toggle ExtensibilityBehavioral Also known as Feature Flag Intent Used to switch code execution paths based on properties or groupings. Allowing new features to be released, tested and rolled out. Allowing switching back to the older feature quickly if needed. It should be noted that this pattern, can easily introduce code complexity.
These toggles are mainly used for testing purposes. The toggle splits the user base into different segments to expose an isolated segment to the new feature. The usage data for the segmented users are used to infer the effect of the new feature. As it’s only used for testing purposes, the toggles can be removed once the testing is done. 3.
"Toggle" is a more appropriate name when code is turned on or off for a few major code branches. "Flag" is a more appropriate term if a decision point is followed by a very multi-conditional or broad set of codepaths. Applying feature toggles to your development process supports newer agile approaches.
if-then-else
(or switch-case
for multi-state switches)I, personally, prefer to use plain if-then-else
constructs, decorated with a comment saying TODO: Remove when feature has been tested.
when applicable.
Keep in mind that every feature flag is a technical debt. Do not overuse them. I recommend against using them for business logic.
However, regarding your spaghetti ball of business toggles, I would recommend a refactoring.
If that is not enough, you can model the business logic with a graph (e.g. decision flowchart) or a Matrix and use the respective standard algorithms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With