Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downsides to using a single ActionListener for all Components?

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 ?

like image 998
James P. Avatar asked Dec 11 '22 23:12

James P.


1 Answers

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.

like image 75
ChriWeis Avatar answered May 09 '23 01:05

ChriWeis