Allowing a program to enable/disable some functionalities
Hi,
I have developed an application that allows an user to perform several operations.
Now, I need to add a new feature to it: some operation is classified "unsafe". The application can therefore be run in two modes: safe mode (allows only safe operations) and unsafe mode (allows safe and unsafe operations).
What would be a good OO implementation or pattern for that?
Firstly I came up with the following simplistic design:
"safety mode" is stored in a static flag variable in a specialized class, accessible with getter and setter methods. A system property or a password-protected menu option allows the user to set the safety to "safe" or "unsafe". A simple if-then-else construct enables or disables components, depending on the flag, allowing or denying the user from performing that operation.
Thanks, any comment appreciated.
# 2
In one design, the variable can be stored in a configuration file, e.g. Properties file , web.xml. Relevant classes are then coded to read this variable and execute conditional processing based on the value.
If Users are allowed to set the safety to "safe" or "unsafe", how "safe" is that? Doesn't sound too secure in my opinion. Might need to rethink this part.
# 4
> In one design, the variable can be stored in a
> configuration file, e.g. Properties file , web.xml.
> Relevant classes are then coded to read this variable
> and execute conditional processing based on the
> value.
This was more or less my design -- except that it sounds cooler as you formulated it ;-)
> If Users are allowed to set the safety to "safe" or
> "unsafe", how "safe" is that? Doesn't sound too
> secure in my opinion. Might need to rethink this part.
Safety change from inside the application requires a password.
Users cannot choose the safety by setting the relevant system property as they have access to bytecode only.