For routing action requests, I'd like to use a single ActionListener instance for all Components. Calls on actionPerformed could be differentiated using setActionCommand.
Is this advised ? Are there any potential downsides to this approach in an MVC context ?
MVC only dictates to split M, V and C. It does not mandate some kind of cardinality for the relationships though. So you're free to go.
If the switch logic inside the event-handling method gets too complex (like more than a few lines), you might want to think about splitting the one huge class into multiple classes. Provides better overview and maintenance. Believe me: if you get back to a simple Listener to change it, you will be really happy. This would be a Refactoring then; your IDE might provide according support.
So my advise: KISS - do it simple first an put your stuff in one Listener. If it gets too complex: make it simple again and refactor to multiple Listeners (that would be another application of KISS).
Just remember to keep your code simple and don't be lazy creating classes. Creating a class is way more simple than getting your head back into complex code. Always remember: creating software is 20%, maintenance is 80%. Make the code simple to understand now and maintenance will be simple later. The opposite applies either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With