I learn Java and create a small project that contains a form. It has a lot of buttons, so you need a lot of Listeners. The book recommends to implement them all with the help of inner classes.

Is it worth taking all the Listeners to a separate class and implementing them as internal classes (maybe there is some design pattern) or leaving everything in one class (creating the interface in it)?

How should organize classes so that you can easily add new functionality without digging hundreds of lines of code?

  • @PashaPash Thank you for correcting. it was impossible to read - arg

1 answer 1

Different Listeners are designed for different purposes. It is in accordance with these goals that the hierarchy of these classes should be organized. And the fact that they implement the Listener interface only means that, among other things, they react to button presses and other user actions. This is a secondary sign, do not rely on it.