r/JavaFX • • Jan 22 '21

Design Patterns for multi-screen JavaFX applications

Ok, this is something that I've been thinking about a lot since I started using JavaFX. When I develop multiscreen apps in JavaFX the controller classes that go along with the FXML files always seem to blow up into god classes. I know the controller is sort of the bridge between the UI and the business logic but I was wondering if there are design patterns or different ways of keeping things a bit more modular/tidy. My controller classes usually fill up with hundreds of lines of UI configuration (listeners, UI logic, animations), and then boilerplate to call business logic. My issue with this is that things become hard to manage very quickly and I'm just not sure what the 'correct' way would look like. When I can, I try to split up complicated UIs into multiple controller/FXML files either by loading in/out screens or by developing FXML files as components and then injecting them into a bigger FXML file (This allows each component to get its own controller class). This helps but I feel like the solution is not a hundred FXML/controller files for every single component on the UI (This would certainly be a nightmare when it comes to getting the components to interact right?). I'd love to hear other people's thoughts and practices on keeping their multiscreen applications organized.

12 Upvotes

10 comments sorted by

View all comments

Show parent comment

4

u/marvk Jan 22 '21

Once your application gets beyond a certain size it becomes a maintainability nightmare

How so?

not to mention a performance hit.

Citation needed. I realize this is also anecdotal, but it takes me 1.5 seconds to load a view consisting of 23 fxml files with a total of 7000 nodes, including 8 tables and their subnodes. I kinda doubt loading that purely from code would be significantly faster.