Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with monstrous Struts Actions?

I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a specific question regarding Actions. Most of the pages have exactly one Action, and the processExecute() methods are hideous monsters (very long and tons of nested if statements based on request parameters).

Given that Actions are an implementation of the command pattern, I'm thinking to split these Actions into one Action per user gesture. This will be a large refactoring though, and I'm wondering:

  1. Is this the right direction?
  2. Is there an intermediate step I could take, a pattern that deals with the mess inside the monolithic actions? Maybe another command pattern inside the Action?
like image 303
thvo Avatar asked Oct 16 '08 17:10

thvo


1 Answers

My way of dealing with this would be:

  • dont do 'everything at once'
  • whenever you change anything, leave it better than you found it
    • replacing conditionals with separate Action implementations is one step.
    • Better yet: Make your implementations separate from the Action classes so that you can use it when you change frameworks
    • Keep your new Command implementation absolutely without references to Struts, use your new Actions as Wrapper around these implementations.
    • You might need to provide interfaces to your Struts ActionForms in order to pass them around without copying all the data. On the other hand - you might want to pass around other objects than ActionForms that are usually a bunch of Strings (see your other question about Struts 1.2 ActionForms)
  • start migrating parts to newer & better technology. Struts 1.2 was great when it came out, but is definitely not what you want to support in eternity. There are some generations of better frameworks now.

There's definitely more - Sorry, I'm running out of time here...

like image 62
Olaf Kock Avatar answered Sep 28 '22 20:09

Olaf Kock