I'm currently working on a legacy system using Oracle's ADF Faces JSF implementation for the presentation layer. The system relies on a rules engine to make certain form elements required, disabled, or even highlighted depending on the user's interaction with them or values entered.
At it's current stage the application is "working", sort of. The current implementation handling the rules engine and the front end updates isn't very elegant and consists of a large set of if statements similar to:
if(screenObj instanceof CoreInputText) {
((CoreInputText) screenObj).setDisabled(true);
}
To complicate the mix we also have our own objects mixed in so the set as a whole does not share a common ancestor thus eliminating our option of doing something like:
((CommonAncestor) screenObj).setDisabled(true);
The question is whether or not it would be worth reworking this portion of the code to be cleaner and clearer. Because the majority of the screen elements are ADF Faces elements we're not able/allowed to change their ancestry to add additional methods.
The goal of the code change would be two fold: clean up older code and improve the code base so that the addition of new elements or controls won't result in a large code change (specifically to the if statements which exist in numerous places).
So if we go forward with this change which would be the better choice of achieving what we're looking for? Subclassing all of the elements (requiring a new class each time we utilize another pre-existing control) or implementing the decorator pattern? My only concern with the decorator is that it would still require a code change for each additional element. Both options would appear to reduce the code changes since multiple methods containing these if blocks wouldn't need updating.
Any input on methods for handling such situations beyond subclassing and decorators is welcome!