I need to hide some menu options in the production environment, but not in development.
I implemented this as an enum like this:
public enum Functionality {
FUNCTION_1(true),
FUNCTION_2,
FUNCTION_3(true);
private boolean usable;
Functionality() {
this(false);
}
Functionality(boolean usable) {
this.usable = usable;
}
public boolean isUsable() {
return usable;
}
}
And then, when I need to show the menu options, I check whether that functionality needs to be shown.
So I need to be able to change the usable boolean when the environment is development. But I cannot find any way to do it in Spring.
Do you know of a way to do something like this?
You could change the fields of an
enum, but it’s usually considered a bad idea and is often a design smell.A better approach would possibly be to not have
usablebe a field at all, instead make it a calculated property:Obviously there would need to be a method like
SystemConfiguration.isDevelopmentSystem()for this to work.In some systems I implemented I used another
enumfor this:Here I used a system property to specify the type at runtime, but any other configuration type might be just as appropriate.