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.

[879 byte] By [java_knighta] at [2007-11-27 7:03:24]
# 1
some plugin style system where the "unsafe" functionality doesn't get loaded when not authorised is probably cleanest (but may require quite some rearchitecturing if you've not prepared the system to use something like that from the outset).
jwentinga at 2007-7-12 18:54:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 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.

GhostRadioTwoa at 2007-7-12 18:54:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
I suppose you've read a bit about the decorator and abstract factory patterns?
r035198xa at 2007-7-12 18:54:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 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.

java_knighta at 2007-7-12 18:54:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
The Decorator didn't seem appropriate but the Abstract Factory is interesting -- I didn't think about it.Thanks to you all, now rewarding with Duke Stars :-)
java_knighta at 2007-7-12 18:54:36 > top of Java-index,Other Topics,Patterns & OO Design...