I have read about MVC but am having doubts on how to implement the concept in Java with Swing. Here's what I'm going for:
The model:
ListOfThings
contains a Collection
of Thing
objects.
The controller:
Controller
instanciates ListOfThings
and populates it with a "add" method (internally creates a new Thing
and adds it to the Collection
)
The view:
A Swing interface with a ListOfThingsPanel
which will contain ThingPanel
components to represent the model. Both extend JPanel
. ThingPanel
contains various components meant to display the data of the Thing
it's linked to.
It also has a button which adds a new (empty) thing to the list.
The click event calls the Controller
's addThing()
method which asks ListOfThings
to add a new Thing
to its list. ListOfThings
has an event/listener system and ListOfThingsPanel
listens to it to know when it should refresh the view.
Am I properly following the MVC concept by doing it like this?
Update: I'm still learning Java but I have coding experience and would prefer to learn the theory and attempt it by my own means before using premade frameworks. While I'm aware Swing implements the MVC pattern, I have read it does it in a specific way (View and Controller combined) which might not be the best and not applicable in other circumstances. I'm a bit wary until I can make sure "Swing MVC" is not different from "MVC", or that the differences won't impact my understanding of the underlying ideas.
One thing of import to me is to learn to really separate the model from the view to allow me to ultimately create various views of various types (Swing but also console or update to JavaFX for example) This is why I'd like to avoid anything Swing specific outside of the view part itself.