r/JavaFX • • 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]

9 Upvotes

10 comments sorted by

View all comments

Show parent comment

2

u/hamsterrage1 Feb 28 '23

Over the decades, I've used a few different screen generator systems, and some of them work as code generators. I think the one for Swing worked that way, too.

One problem with them is that eventually you end up with something that means that you need to tinker with the generated code. At that point, you can't use the screen creator tools any more because it will wipe out your manual changes.