I am making a JavaFX application and which has four root controllers. Each of these controls the view on a tab. There is no controller for the tab selector as it has no functionality other than to select which of the four views to show. These controllers are required to have access to identical data and they can all modify this data.
The only way that I can see to achieve this in a way that is readable is with a static singleton which stores state that can be accessed and modified by all four controllers. For obvious reasons, this is not ideal.
I cannot use dependency injection as all controllers are initialised when the app is launched, they are not created by one another. I cannot use the observer patter either for the same reason. They have no way to obtain a reference to each other and thus they cannot observe each other. As far as I know, there is no broadcast notification system in Java which is annoying as it would be a solution. Is there another pattern that I could use or some way I could make one of these pattern work?
The fxml files for the tabs are loaded as content in the tab pane. It is done this way so that I can have a different controller for each tab. The start method then loads the tab pane fxml.
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab text="Data & Statistics">
<content>
<fx:include fx:id="dataViewTabControl" source="DataViewTabControl.fxml" />
</content>
</Tab>
. . .