How to minimize the usage of static variables and objects
- by Peter Penzov
I'm trying to implement this JavaFX code where I want to call remote Java class and pass boolean flag:
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
//DataTabs.renderTab = toolbarSubMenuNavigation.isSelected();
DataTabs.setRenderTab(toolbarSubMenuNavigation.isSelected());
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
Java class which I want to call:
public class DataTabs
{
private static boolean renderTab; // make members *private*
private static TabPane tabPane;
public static boolean isRenderTab()
{
return DataTabs.renderTab;
}
public static void setRenderTab(boolean renderTab)
{
DataTabs.renderTab = renderTab;
tabPane.setVisible(renderTab);
}
// somewhere below
// set visible the tab pane
TabPane tabPane = DataTabs.tabPane = new TabPane();
tabPane.setVisible(renderTab);
}
This implementation works but I want to optimize it to use less static variables and objects. Can you tell me which sections of the code how can be optimized?