AhFai Chan wrote:Working thru books and when looking up Oracle's demos and samples for guidance, the codes that used to be in Controller are now together with the Modal and View i.e. the user interacts with the GUI and the setOnAction bits are all in the same class
Yes, it's quite common for Swing code (and now JavaFX code too) to have controller code and GUI code intermingled. Or at least, to appear that way; for example code creating a GUI component is obviously part of the View, but then you might add a listener to the GUI component. The code inside that listener is part of the Controller, as it's going to interact with the Model or the View or both, but it does appear to be in the same class. You can make the point that the listener code is in an anonymous inner class, which is separate from the class which contains it, but when you change the anonymous inner class to a lambda expression then it's harder to believe that.
You could be fastidious about MVC and require that the listener should do nothing but call some code which is in a class defined as "Controller" code in the architecture. For example, create a separate class which implements whatever listener and then use an instance of that class. Personally I haven't done that very much, I just mentally note that the listener code is part of the Controller.
Also, a lot of the tutorials were written before the developers of
Java were really into architecture; some of the older ones include bad practices (like extending JFrame) which are still imitated by beginners who read those tutorials. Well-architected code takes more work to write and results in a lot more classes. For example consider Java's first try at date-handling: there was basically Date, Calendar, and TimeZone and a few other supporting classes. When the architects got through redesigning that horribly flawed set of classes they produced the java.time package with its 15 classes along with four other packages for non-standard time systems, date and time formatting, working with date and time components, and time zones. I count 39 classes in total plus a non-trivial number of interfaces and enums.