Our organization relies heavily on Public Site Visual Force pages for data collection from our user community. These sites contain about a dozen or so VF Pages. The entire site controlled by a single controller.
As a result, our code base contains some huge monolithic controllers - exceeding 3,000 lines of code. Managing and maintaining these controllers is a huge PITA. They become a spiderweb of action methods that becomes increasingly difficult to debug and modify. I want to kill these controllers with fire.
Most of the pages contain a Back, Next, and Exit button with the occasional page specific button. The actions behind each Back, Next, and Exit button can differ depending on the current page and state of the progress through the site.
I contemplated using a State Pattern to facilitate the functionality of page navigation (e.g. on the Welcome Page the Next action only returns a Page Reference to the Instructions Page, on the Edit Record Page, the Next runs validation on the record and adds it to a list.)
However, I am getting stuck trying to figure out how to handle the dependency injection, various action method signatures, and handling return value assignments without creating separate action methods for each action (i.e. some Next Action methods would need to act on a list of records, modify them, then return the modified result back to the controller while others would simply advance to the next Page Reference).
Does anyone have any advice on how to construct better Controllers that don't turn into monolithic monstrosities?