From what I understand and from what I've read, MVC in JavaFX has different interpretations and variations. I was previously coding my app in a very disorganized way that used many static variables, lacking proper modularity, so I want to organize it. I've had experience in MVC, just not in JavaFX.
Since I have only one Scene in my app, which is a BorderPane
, my view would simply be the different nodes that make up the BorderPane
. I have all these nodes already made in SceneBuilder and thus a corresponding FXML file. I only have one FXML file and one Controller.
The center pane would allow for the user to dynamically create different objects, and those objects, such as their quantity and values, would be within the model.
Lastly, my Controller class would be responsible with managing the view changes, such as when the user wants to create new objects, and general interactability. It would also handle communication between the BorderPane
regions.
I'm trying to take some inspiration from this post here with how to implement MVC, but one thing I can't figure out are where the store the listeners for these dynamically created objects. For example, my project would have user-created nodes and lines connecting them, which are classes I made. The nodes can be right clicked and dragged, and the thus the line would be dynamically recalculated. I previously attached the listeners to my nodes and lines to classes or objects themselves: either in the constructor or a method that removes/adds listeners/handlers, but I would assume that breaks the MVC pattern and modularity? I also previously had many static variables which again is bad design.
How can I best modularize my code to adhere to MVC, with dynamically created, interactable objects in the view? Which class would handle the events for these objects? Is all responsibility for interaction delegated to the Controller class itself?