I have implemented the following simplyfied structure using JavaFX:
App.java
public void start(Stage primaryStage) {
MyConnector myconnector = new MyConnector();
LeftPane leftPane = new LeftPane(myconnector);
RightPane rightPane = new RightPane(myconnector);
}
MyConnector.java
public class MyConnector {
private Button button; // getters, setters
private Field field; // getters, setters
}
LeftPane.java
public LeftPane extends FlowPane {
private Button button; // getters, setters
private MyConnector myConnector; // in constructor, getters, setters
public LeftPane(myConnector) {
this.button = new Button();
this.myConnector = myConnector;
this.myConnector.setField(this.button); // add to the MyConnector
}
an event on action {
this.myConnector.getField().setEditable(false);
this.button.setDisable(true);
}
}
RightPane.java
public RightPane extends FlowPane {
private TextField field; // getters, setters
private MyConnector myConnector; // in constructor, getters, setters
public LeftPane(myConnector) {
this.field = new TextField();
this.myConnector = myConnector;
this.myConnector.setField(this.field); // add to the MyConnector
}
an event on action {
this.myConnector.getButton().setDisable(true);
this.field.setEditable(false);
}
}
Shortly it means, that I have two panes containing the first one the Button
and the second one the TextField
. On some event triggers, I want to disable both of them at once. This solution works perfectly.
I wanted firstly avoid this cross-like code, that leads to the NullPointerException
only:
LeftPane leftPane = new LeftPane(this.rightPane.getField());
RightPane rightPane = new LeftPane(this.leftPane.getButton());
Is the structure above I have used the correct approach and is it one of design patterns? If so, what is it's name? I've been thinking over Adapter
or Bridge
but I can't parse my structure into one of them.
If my structure isn't a design pattern at all, does exist the one dealing with the same thing or does exist a better aproach?
Aucun commentaire:
Enregistrer un commentaire