Mvc – Good design patterns within JavaFX — MVC

design-patternsgui designjavafxmvc

I have used a lot of JavaFX and am familiar with the technical aspects. Now, as I foray into a very large application with hundreds of views, I want to make sure I start strong with a solid design. This is purely a client application, backend is elsewhere.

I should also mention this is an MDI (Multiple document interface) application, which only worsens complexity.

Skip to the tl;dr if you don't want to read the following rant.

In my mind, the controllers should not communicate with each other. Each part of the system should be modular and unaware of the other parts, with some master controller stringing them all together. I'm not sure how this is achievable within JavaFX. This is worsened by the fact that there be many instances of an FXML view/controller within the MDI (I'll call it MDIRoot).

This example HERE is the closest thing I've liked, but there are a few obvious problems. The main problem with this is in the example, all of the controllers will exist for the duration of the program. But many even semi-complex applications will have FXML controllers that don't exist at all times. So how do I initialize the MainController instance of the other controllers? The other obvious issue is that in my case, there can be many instances of a controller. So I'd need the MainController to have a list for each controller. The third problem, is that MainController is just the FXML controller for the root of the project, which in my case (MDI) has it's own logic. Shouldn't something worthy of being a "main" controller be completely independent of its own logic, and focus entirely on encapsulating the other controllers?


tl;dr: I'm having trouble finding a way to effectively use MVC (or MVP, or anything that's suggested really) for a large scale MDI application in JavaFX. If anyone has examples or input or anything I would appreciate it. Code samples would be nice, or even JavaFX-specific explanations of how to implement nice design when the application gets large (with the one requirement that the controllers don't talk to each other).

Best Answer

Check out this sweet framework, i fell inlove with this and i think you will too!

https://github.com/AdamBien/afterburner.fx

Here is my example:

https://github.com/urosjarc/headhunt

Hope it helps...

Related Topic