1. Why MVCI?
In a small JavaFX application, it is tempting to put UI event handlers, database calls, validation, and screen updates in the same controller class. This works initially, but makes features harder to test and change as the application grows.
MVCI separates four responsibilities: state, presentation, coordination, and application logic. It builds on familiar JavaFX properties and listeners rather than replacing them.
Model
Stores observable state, properties, and messages.
View
Builds JavaFX nodes, observes the Model, and forwards user intentions to the Controller.
Controller
Coordinates its MVCI unit, delegates work to the Interactor, and routes cross-feature requests through MainController.
Interactor
Executes business operations and updates Model state, without direct View or Controller access.
Use these resources to explore, understand, and start building with MVCI
2. The View
The View is the presentation layer of an MVCI unit. It is responsible for constructing the JavaFX user interface, displaying state from its Model, responding to changes in that state, and reporting user actions to its Controller.
No FXML. This system builds every View entirely in Java code. It does not use FXML and is not compatible with it. Views are assembled through the JavaFX functional Interface Builder<T>, and the base classes depend on that structure. FXML's own controllers and injection would conflict with the Model, Interactor and message flow described here.
The View may directly access its own Model. It does not directly access the Interactor, repositories, other MVCI units, or application business logic.
The View's Role
In this implementation of MVCI, the View has two primary communication paths: one for sending user intent out of the View and another for receiving state changes and UI requests through the Model.
User Action → View → Action Enum → Controller
Interactor → Model → View
These two paths are intentionally separate. The View reports what the user requested, but does not decide how the request should be processed. The Interactor performs the work and changes the Model. The View then responds to the resulting Model state.
View Responsibilities
- Construct the JavaFX scene graph for the MVCI unit.
- Own and configure its JavaFX controls.
- Read observable state from its Model.
- Bind controls to Model properties when appropriate.
- Listen for changes to Model properties.
- Respond to explicit View-message enums exposed through the Model.
- Convert user interactions into action enums sent to the Controller.
- Perform presentation-only operations such as refreshing or changing visible controls.
What Does Not Belong in the View
The View should contain presentation logic, not application business logic. Code that retrieves, modifies, validates, or coordinates application data belongs elsewhere in the MVCI unit.
| The View Can | The View Should Not |
|---|---|
| Access its own Model | Access the Interactor directly |
| Read and observe Model properties | Access repositories |
| Build and update JavaFX controls | Perform business logic |
| Send action enums to its Controller | Coordinate another MVCI unit |
| React to View-message enums | Modify application data outside its Model |
ViewBase
Views share a common structure through ViewBase. A concrete View extends this base class and
supplies the Model and the action enum used by its MVCI unit.
The base class establishes the common contract while each concrete View remains responsible for constructing its own JavaFX interface.
package com.L2.interfaces;
import javafx.util.Builder;
import java.util.function.Consumer;
public abstract class ViewBase<T, M, MSG> implements Builder<T> {
protected final M model;
protected final Consumer<MSG> action;
protected ViewBase(M model, Consumer<MSG> action) {
this.model = model;
this.action = action;
}
protected abstract void viewListener();
}
Builder<Region>, building the View produces the Region that
becomes part of the application's scene graph.
User Actions Leave the View Through an Action Enum
When the user interacts with a control, the View does not call the Interactor. Instead, the View describes the user's request using the action enum belonging to that MVCI unit.
refreshButton.setOnAction(event ->
action.accept(NoteAction.REFRESH)
);
Button → NoteAction.REFRESH → Controller
This is an important boundary. The View knows that the user requested a refresh, but it does not need to know what operations are required to perform that refresh. The Controller receives the action and delegates the appropriate work to the Interactor.
The View Observes the Model
Information coming back to the View takes a different path. The Interactor changes the Model, and the View observes those changes.
Interactor → Model Property → View
For ordinary application state, JavaFX properties provide the communication mechanism naturally. A View can bind a control directly to a Model property or attach a listener when the UI requires additional presentation logic.
model.statusProperty().addListener(
(observable, oldValue, newValue) ->
statusLabel.setText(newValue)
);
This means the Controller does not need to tell the View that the state changed. The Model itself is observable.
Explicit View Messages
Not every UI operation can be represented conveniently as ordinary persistent state. Sometimes the Interactor needs to signal that the View should perform a particular one-time presentation operation.
For those cases, the Model contains a property whose value is a View-message enum. The View listens to that property and handles the requested operation.
model.messageProperty().addListener(
(observable, oldValue, newValue) -> {
switch (newValue) {
case REFRESH_DETAILS -> refreshDetails();
case NO_REQUEST -> { }
}
}
);
Interactor → Message Property in Model → View Listener → UI Operation
This keeps the direction of communication intact. The Interactor does not call a method on the View. Instead, the Interactor changes Model state, and the View responds to that state.
State Versus Messages
Model properties and View-message enums serve different purposes and should not be treated as interchangeable mechanisms.
| Model Property | View Message |
|---|---|
| Represents application state | Represents a specific UI request |
| Can remain at its current value | Typically represents a one-time operation |
| Well suited to JavaFX bindings | Well suited to a listener and switch statement |
| Example: selected note or status text | Example: refresh or clear a portion of the UI |
The View Does Not Need to Know How the Work Is Done
One of the most useful consequences of this separation is that the View can remain focused on presentation even as the application becomes more complex. A button may eventually cause database access, calculations, communication with another MVCI unit, or several other operations. None of that complexity needs to move into the View.
User → View → Controller → Interactor → Model → View
From the View's perspective, its responsibility remains simple: report the user's intent, observe its Model, and present the resulting state.
3. The Controller
The Controller coordinates an MVCI unit. It owns the Model, Interactor, and View, connects them together, and provides the boundary through which the View communicates with the rest of the application.
The Controller coordinates work; it should not perform the work itself. Business logic and data operations belong in the Interactor.
The Controller as the MVCI Coordinator
A Controller has two primary responsibilities: constructing its MVCI unit and routing requests to the correct component.
NoteController.class
An example of a a Controller structured by the abstract ControllerBase.class
public class NoteController extends ControllerBase<
NoteModel,
NoteInteractor,
NoteView,
NoteAction> {
public NoteController(MainController mainController) {
super(mainController);
initializeMVCI();
}
@Override
protected NoteModel createModel() {
return new NoteModel();
}
@Override
protected NoteInteractor createInteractor(NoteModel model) {
return new NoteInteractor(model);
}
@Override
protected NoteView createView(NoteModel model) {
return new NoteView(model, this::action);
}
@Override
public void action(NoteAction action) {
switch (action) {
case REFRESH -> interactor.refreshNotes();
case SAVE -> interactor.saveNote();
}
}
}
What the Controller is doing
✓ Controller responsibilities
- Create the Model, Interactor, and View.
- Receive actions from the View.
- Delegate requests to the Interactor.
- Coordinate communication with other Controllers.
- Expose the built View to the application.
✗ Not Controller responsibilities
- Querying a Repository directly.
- Saving or loading application data.
- Manipulating JavaFX controls directly.
- Storing application state.
- Implementing business logic.
When an action requires real work, the Controller should usually be able to express its response in a
single delegation such as
interactor.refreshNotes().
4. The Interactor
The Interactor contains the application logic for an MVCI unit. The Controller delegates requests to the Interactor, and the Interactor performs the work required to satisfy that request.
The Interactor performs the work, then expresses the result by updating the Model. It can communicate with Repositories and services, but it should never manipulate JavaFX controls directly.
The Interactor as the Application Logic
An Interactor sits between the Controller, the application's data sources, and the Model. It receives an operation from the Controller, obtains or changes data as necessary, and updates observable Model state with the result.
Java
public class NoteInteractor extends InteractorBase<NoteModel> {
private final NoteRepository noteRepository;
public NoteInteractor(
NoteModel model,
NoteRepository noteRepository) {
super(model);
this.noteRepository = noteRepository;
}
public void refreshNotes() {
List<NoteDTO> notes =
noteRepository.findAll();
model.getNotes().setAll(notes);
}
}
What the Interactor is doing
✓ Interactor responsibilities
- Implement application and business logic.
- Query and update Repositories.
- Coordinate multiple data operations.
- Transform retrieved data when necessary.
- Update properties and collections in the Model.
✗ Not Interactor responsibilities
- Creating or modifying JavaFX controls.
- Changing Labels, TableViews, or other View elements.
- Building the scene graph.
- Responding directly to button events.
- Coordinating directly with another MVCI's components.
A useful rule is that the Interactor may change application state, but it should not change UI controls. The Interactor updates the Model; observable Model state allows the View to reflect that change.
5. The Model
The Model holds the observable state for its MVCI unit. Its properties provide the shared state through which the Interactor and View communicate.
The Model represents state, not behavior. The Interactor changes that state, and the View observes it.
The Model as Observable State
Model properties are initialized when they are declared and exposed through property getters. This keeps the Model simple, observable, and independent of the rest of the MVCI unit.
Java
public class NoteModel {
private final StringProperty status =
new SimpleStringProperty("");
private final ObjectProperty<NoteMessage> message =
new SimpleObjectProperty<>(
NoteMessage.NO_REQUEST
);
public StringProperty statusProperty() {
return status;
}
public ObjectProperty<NoteMessage> messageProperty() {
return message;
}
}
What the Model is doing
StringProperty
""
ObjectProperty<NoteMessage>
NO_REQUEST
✓ Model responsibilities
- Hold JavaFX properties and application state.
- Expose properties through getters.
- Provide observable state to the View.
- Hold the View-message property when needed.
- Initialize properties where they are declared.
✗ Not Model responsibilities
- Performing business logic.
- Accessing Repositories.
- Manipulating JavaFX controls.
- Calling the Controller or Interactor.
- Coordinating with another MVCI unit.
6. The communication rules
These are the conventions used in this application. They are deliberate architectural rules, not automatic restrictions imposed by JavaFX.
| Component | Direct access | Communication |
|---|---|---|
| View | Its Model | Action enum callback to Controller |
| Controller | Its Interactor; construction references to Model and View | Interactor method calls; other Controllers through MainController |
| Interactor | Its Model | Changes Model properties and View-message enums |
| Model | Its own state | Observable properties |
Two directional message paths
User action: View → Controller action(enum) → Interactor → Model
Screen update: Interactor → Model property/message → View listener → JavaFX UI
Bindings and property listeners handle ordinary state changes; explicit View messages are useful for one-time UI commands.
MVCI Within a Single Feature
Messages flow in one direction through the MVCI components.
View
JavaFX UI
Sends action to
Controller
Controller
Receives action,
coordinates request,
delegates to Interactor
Interactor
Performs business
logic and updates
Model
Model
Holds application
state (JavaFX properties)
Notifies observers
The View observes Model properties and updates the UI automatically.
Key Points
- Messages flow in one direction within an MVCI unit.
- The View sends an action enum to the Controller.
- The Controller delegates work to the Interactor.
- The Interactor updates the Model.
- The View observes Model changes and updates the UI.
Each MVCI unit has its own:
- Model class
- View class
- Controller class
- Interactor class
- Action enum (View → Controller)
- Message enum (Interactor → View via Model)
Two ways an MVCI operation begins
An MVCI unit can respond either to its own View or to a request coordinated from another MVCI unit. Both paths converge on the Interactor updating the Model, after which the View observes the changed state.
User-initiated flow
View sends an action enum to its Controller → Controller delegates to Interactor → Interactor updates Model → View observes Model and updates UI
Message enums: two distinct directions
Each MVCI unit defines its own message vocabulary. Keep messages for View-to-Controller actions separate from messages that tell its View to perform an explicit operation. Enum names vary by feature; NoteAction and NoteMessage below are illustrative.
| Enum | Direction | Purpose |
|---|---|---|
NoteAction |
View → Controller |
Expresses a user request such as REFRESH, passed through action.accept(...).
|
NoteMessage |
Interactor → Model property → View |
Signals an explicit UI operation such as REFRESH_DETAILS; the View's single message
listener switches on the enum.
|
Not every Model change needs a message enum. Ordinary observable properties and bindings already notify the View. Use View messages when a deliberate UI command is needed, and reset a message property appropriately if the same enum value may be sent repeatedly.
Programmatic or cross-MVCI flow
Another MVCI Controller coordinates through MainController → Target Controller delegates to its Interactor → Interactor updates its own Model → Target View observes its Model and updates UI
Message enums: two distinct directions
Each MVCI unit defines its own message vocabulary. Keep messages for View-to-Controller actions separate from messages that tell its View to perform an explicit operation. Enum names vary by feature; NoteAction and NoteMessage below are illustrative.
| Enum | Direction | Purpose |
|---|---|---|
NoteAction |
View → Controller |
Expresses a user request such as REFRESH, passed through action.accept(...).
|
NoteMessage |
Interactor → Model property → View |
Signals an explicit UI operation such as REFRESH_DETAILS; the View's single message
listener switches on the enum.
|
Not every Model change needs a message enum. Ordinary observable properties and bindings already notify the View. Use View messages when a deliberate UI command is needed, and reset a message property appropriately if the same enum value may be sent repeatedly.
7. Example communication: a button click
Suppose a View has a Refresh button. The View reports intent, the Controller delegates the work, and the Interactor queries a Repository and updates the Model. The communication path only flows in one direction.
The following diagram shows the complete Refresh operation. The numbered arrows correspond to the event log beneath the diagram.
// View
refreshButton.setOnAction(e -> action.accept(NoteAction.REFRESH));
// Controller
@Override
public void action(NoteAction actionEnum) {
switch (actionEnum) {
case REFRESH -> interactor.refreshNotes();
}
}
// Interactor
public void refreshNotes() {
// Query services/repositories and update Model properties.
// Do not directly modify TableView or Label controls.
}
The View can bind controls to Model properties, so many state changes require no explicit View message. Use messages for intentional UI commands rather than every observable data change.
8. Programmatic communication between MVCI units
Not every MVCI interaction starts with a button click. One feature may complete work that requires another feature to update its own state and UI. For example, after a Part Order is saved, the Note feature may need to refresh its related information.
Key rule: one MVCI unit does not reach into another unit's Model, View, or Interactor.
Cross-feature coordination goes through MainController. Each Interactor updates its own Model,
and each View observes its own Model.
References and action signals to other models can be passed from one mvci to the main controller and then
to another mvci.
Sequence
-
PartOrderInteractor completes its operation and updates
PartOrderModel. - PartOrderController requests a Note refresh through
MainController. - MainController routes the request to
NoteController. - NoteController delegates to
NoteInteractor. - NoteInteractor loads the relevant data and updates
NoteModel. - NoteView observes the property change and updates the UI.
Illustrative Java coordination
// PartOrderController: called when its save operation completes
private void onPartOrderSaved(long noteId) {
mainController.requestNoteRefresh(noteId);
}
// MainController: central cross-feature coordinator
public void requestNoteRefresh(long noteId) {
noteController.refreshRelatedNote(noteId);
}
// NoteController: delegates to its own Interactor
public void refreshRelatedNote(long noteId) {
interactor.refreshRelatedNote(noteId);
}
// NoteInteractor: updates only its own Model
public void refreshRelatedNote(long noteId) {
// Retrieve current note information from a repository.
// Update NoteModel's observable state.
}
// NoteView: observes NoteModel and updates UI automatically
// through bindings or property listeners.
The method names above are illustrative, not claims about existing TSE Notes APIs. The important feature is the communication boundary, not a particular callback or method signature.
9. The abstract base classes
These shared classes reduce repetitive setup and establish a consistent structure across features. Each concrete MVCI unit supplies its own types.
InteractorBase<M>
Owns a strongly typed, final Model reference. Concrete Interactors implement business operations.
package com.L2.interfaces;
public abstract class InteractorBase<M> {
protected final M model;
protected InteractorBase(M model) {
this.model = model;
}
}
ViewBase<T, M, MSG>
Implements Builder<T>, stores a strongly typed Model reference, and provides the common
structure used by concrete Views. Each View is responsible for building its JavaFX scene graph and
registering its Model-to-View listener.
package com.L2.interfaces;
import javafx.util.Builder;
/**
* Base class for Views in the MVCI architecture.
*
* <p>The View owns the construction of its JavaFX scene graph and maintains
* a reference to the Model that provides its observable state.</p>
*
* @param <T> root type produced by build()
* @param <M> Model type
* @param <MSG> message Enum used for Model-to-View communication
*/
public abstract class ViewBase<
T,
M,
MSG extends Enum<MSG>>
implements Builder<T> {
protected final M model;
protected ViewBase(M model) {
this.model = model;
}
/**
* Registers the listener used for explicit
* Model-to-View messages.
*/
protected abstract void viewListener();
/**
* Builds and returns the root of the JavaFX scene graph.
*/
@Override
public abstract T build();
}
ControllerBase<M, I, V, A>
Standardizes Model → Interactor → View initialization and caches the Region on first getView(). The private View field discourages direct View method calls.
package com.L2.interfaces;
import javafx.scene.layout.Region;
import javafx.util.Builder;
/**
* Base class for controllers in the MVCI architecture.
*
* <p>The Controller owns the Model, Interactor, and View for its MVCI unit.
* Concrete controllers decide how each part is created by implementing
* the create methods, then call {@link #initializeMVCI()} in their
* constructor.</p>
*
* @param <M> Model type
* @param <I> Interactor type
* @param <V> View type (a Builder that produces a Region)
* @param <A> action Enum used for View-to-Controller communication
*/
public abstract class ControllerBase<
M,
I,
V extends Builder<Region>,
A extends Enum<A>> {
protected M model;
protected I interactor;
private V view;
/**
* The Region produced by the View. It is built once, on first request.
*/
private Region region;
protected abstract M createModel();
protected abstract I createInteractor(M model);
protected abstract V createView(M model);
/**
* Handles actions sent from the View to the Controller.
*
* @param actionEnum action requested by the View
*/
public abstract void action(A actionEnum);
/**
* Creates the MVCI components in order: Model, Interactor, View.
* Call this from the concrete Controller's constructor.
*/
protected final void initializeMVCI() {
model = createModel();
interactor = createInteractor(model);
view = createView(model);
}
/**
* Builds and returns the JavaFX Region for this Controller's View.
*
* <p>The View is a {@link Builder}. The first call runs
* {@code view.build()} and caches the result. Later calls return
* the same Region, so the scene graph is never built twice.</p>
*
* @return the Region for this Controller's View
*/
public final Region getView() {
if (region == null) {
region = view.build();
}
return region;
}
}
Alongside these abstract classes, each MVCI unit typically defines enum types for its communication: View actions sent to the Controller and View messages published through its Model. The abstract classes provide the wiring; the enums give requests clear, type-safe names.
10. Why initialization order matters
JavaFX property listeners run synchronously. If ADD_TAB is sent before MainView registers its listener, the signal is missed.
@Override
public Region build() {
viewListener(); // Before startup actions
BorderPane root = new BorderPane();
// Build layout and then trigger startup operations.
return root;
}
11. What the base classes do and do not guarantee
| Benefit | Qualification |
|---|---|
| Consistent initialization | Concrete Controllers call initializeMVCI(). |
| One Region per Controller | getView() caches its first successful build. |
| Typed action callback | Concrete Views use action.accept(...). |
| Encapsulated View field | Does not prevent every alternate reference. |
| Model-driven updates | Register listeners before messages are sent. |
| Testable logic | Inject repositories and services where practical. |
12. Practical checklist for a new MVCI feature
- Create a Model with JavaFX observable properties.
- Create an Interactor extending InteractorBase.
- Define the View-to-Controller action enum.
- Create a View extending ViewBase and implement build() and viewListener().
- Register listeners before triggering startup actions.
- Create a Controller extending ControllerBase and implement factories and action().
- Call initializeMVCI() in the concrete Controller constructor.
- Let MainController launch the unit and obtain its Region with getView().
- Keep View-specific methods out of Controllers and JavaFX controls out of Interactors.
- Test initialization order, event flow, and repeated messages.
13. The guiding idea
The View presents. The Controller coordinates. The Interactor works. The Model remembers.
The abstract base classes make this division repeatable across a large JavaFX application. They do not replace good judgment, but make the architecture easier to follow, review, and maintain.