At my workplace, there are lot of Java/Spring/Spring-Boot based applications which have a common jar added as maven dependency.

This common jar is always used as a SNAPSHOT dependency and I am not allowed to change the version. This is because after version change, they don't want to update the version in 50+ applications. Teams are required to make the changes in common jar which are backward compatible and should not break any other application. (In long term, this common jar would be removed and all applications will be refactored into proper microservices architecture).

Now, I need to make a change in this common jar and need to find a way where the application importing this jar decides whether this new piece of code should be toggled on or not.

This is a spring based jar and I need to make changes in about 10 service classes in it.

  1. I was thinking of creating toggle flag something like below in all 10 classes with default value as false.
private boolean specialFeatureToggle;
  1. Add if/else blocks based on this variable in the service classes where new code is being added.
  2. Then, in the application where I want to enable this feature, I can pass value of special.feature.toggle as true in application.properties or env vars.

But this solution would have private boolean specialFeatureToggle duplicated across multiple classes.

To remove the duplicate code, I can create a FeatureToggleService class and keep this flag only in this class. Other classes depend on this class to know if the feature is toggled on or not.

  1. Does this design looks fine keeping in mind the constraints related to versioning?
  2. Can anyone please suggest any cleaner design for this problem?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.