[coldbox-3.0.0] Event handler inheritance vs controller action dispatch vs modules

Hey there,

I’ve got a question on a design level. Suppose you want to create a new piece of functionality in an existing application that will by and large expose the same features, but with very different layouts and custom rules that come along with the fact it’s going to be used by 2 or more different areas of the application (separate authentication and visibility).

The application flow is similar enough not to warrant 2+ handlers, as most of the code would be duplicated, but is distinct enough that you need to know on each request which ‘area’ you’re serving the functionality to, so that you can load the proper configuration file, set the respective exit handlers etc.

I can come up with 3 approaches:

  1. decide via a URL parameter (or any other volatile way) which setup to load in the preHandler, and remember to incorporate that into ALL URLs. I don’t like this one, because it makes one query string variable a BIG factor in determining application behavior.

  2. In your handler, specify forArea1 and forArea2 functions, that will be used by ALL URLs to this handler, so that you can uniquely identify the ‘setup’ you need to load to proceed with the action. Then if needed, provide the ‘actual’ action via URL variable

?event=myFunctionality.forArea1&action=doStuff ← load config for area1, set exit handlers, invoke doStuff

  1. Have a main handler, that will serve as a base (will never be called directly). Create 2 handlers that extend the main one. Now you have 2 unique handler names, which determine the area of interest. You can do the setup in the preHandler. By virtue of inheritance, you can put the bulk of your code in the base handler, user super.stuff() if needed, and when calling private functions, the ones from the respective handler would be run.

Which one would you pick? Are there other, better alternatives? I’m leaning towards 3, but I haven’t seen much use of handler inheritance for application flow and that may be a sign it’s not really a good direction.

With the way the current application is written, designing a module that would provide the functionality would still leave me with the issue of how to customise it depending on where you are, so it would not be independent. In fact it needs ‘the host’ to have a meaning. I guess it IS the ultimate solution, but for this time I left it out of the list.