In the process of studying the various options for organizing code for the user interface (MVC, MVP, MVVM, MVPVM, and what they call these names), I am a bit confused.
Therefore, as usual, something was done using intermediate interfaces.
And now I ask you to suggest whether this version corresponds to any long-known abbreviation, and where among these three classes and two interfaces are M, V, C, P, VM or their parts and the mixture?
So, approximately, I have the code for a simplified search form:
1) The interface, which indicates which controls and which basic type (basic buttons, text fields, etc.) should be presented in this part of the interface:
public interface IView_SearchForm { TextField getQueryField(); Button getSubmitButton(); TextField getResultsField(); } 2) The implementation of this part of the interface (with design buttons, text fields, etc., which inherit from the base, specified in the interface):
public class View_SearchForm_v11 implements IView_SearchForm { @FXML private YetAnotherTextField txtField1; @Override public TextField getQueryField() { return txtField1; } @FXML private SuperPuperButton button1; @Override public Button getSubmitButton() {return button1;} @FXML private YetAnotherTextField txtField2; @Override public TextField getResultsField() { return txtField2; } } and the corresponding .fxml:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.layout.*?> <VBox fx:controller="View_SearchForm_v11"> <YetAnotherTextField fx:id="txtField1"/> <SuperPuperButton fx:id="button1" text="Submit"/> <YetAnotherTextField fx:id="txtField2"/> </VBox> 3) Interface, which indicates what data and methods should be implemented in the model related to this part of the interface:
public interface IModelAndMethods_SearchForm { StringProperty getQueryProperty(); StringProperty getResultsProperty(); void startSearch(); } 4) Implementation of the data model and methods:
public class ModelAndMethods_SearchForm_v45 implements IModelAndMethods_SearchForm { final private StringProperty queryProperty = new SimpleStringProperty(); @Override public StringProperty getQueryProperty() {return queryProperty;} final private StringProperty resultsProperty = new SimpleStringProperty(); @Override public StringProperty getResultsProperty() {return resultsProperty;} void startSearch() { resultsProperty.set(querySomeOne(queryProperty.get())); } } 5) Associating the interface with data and methods (all the supporting work got into the base class BinderBase<IView,IModelAndMethods> ):
public class Binder_SearchForm extends BinderBase<IView_SearchForm, IModelAndMethods_SearchForm> { @Override protected void bind() { IView_SearchForm v = getView(); IModelAndMethods_SearchForm mm = getModelAndMethods(); addBidirectionalBinding(v.getQueryField().textProperty(), mm.getQueryProperty()); addBidirectionalBinding(v.getResultsField().textProperty(), mm.getResultsProperty()); addAction(v.getSubmitButton(), event -> mm.startSearch()); } } A typical download of all this looks like this:
@Override public void start(Stage primaryStage) throws Exception { ModelAndMethods_SearchForm_v45 modelAndMethods = new ModelAndMethods_SearchForm_v45(); Scene scene = Loader.loadAsScene( View_SearchForm_v11.class, modelAndMethods, Binder_SearchForm.class); primaryStage.setScene(scene); primaryStage.show(); }