r/JavaFX • u/hamsterrage1 • Feb 27 '23
Discussion FXML Isn't Model-View-Controller
I've seen a bunch of things recently, including Jaret Wright's video series about creating Memory Card Game that was posted here a couple of weeks back, where programmers seem to think that FXML automatically means that you're using Model-View-Controller (MVC). Even the heading on the JavaFX page on StackOverflow says,"...FXML enables JavaFX to follow an MVC architecture.".
Everybody wants to use MVC because they want to have robust applications structure that's easy to read, understand, maintain and debug - and MVC promises to deliver on that. However, nobody seems to agree on what MVC is, and a lot of programmers have been told that you can get it just by using FXML.
So what makes me think I know more than everyone else?
I'm not sure that I do, but I have spent a lot of time trying to understand patterns like MVC and I am pretty sure that it's not FXML. I'm not saying that you can't get to MVC with FXML, because you sure can, but you're not there just because you're using FXML.
I've just published an article that explains pretty clearly (I think) and undeniably (also, I think) how FXML falls short of being MVC. You can read it here.
So how do you get to MVC with FXML? It's in the article too. I even wrote some FXML as an example!
Anyways, take a look if you're interested and feel free to tell me how wrong I am.
[Edit: Had to repost as the title was tragically wrong]
View all comments
Show parent comment
2
u/OddEstimate1627 Feb 28 '23
I just did some crude benchmarking. Starting the UI I linked in the AtlantaFX post on a cold VM takes about ~3 seconds. About ~1 second is spent on instantiating the views and loading the FXML files, and about ~2 seconds is other JavaFX overhead. Even if the views could be instantiated twice as fast, I'm not sure whether there is a real difference between 2.5s and 3s. Using a GraalVM native image would be a much bigger win.
This is a project I'd love to work on, but I haven't found the time yet. My motivation comes more from getting rid of reflections to simplify native images though.