You can make it single, but then you need to find another way to insert a simulator into it.
In the current implementation, the simulator is installed for the first time when someone calls the constructor. This constructor is very strange because it sets a static field. It will also immediately open the connection, separate from the connection used by the singleton instance.
If the getInstance () method is called before the constructor is called at least once, the simulator will never be set.
To make it suitable single, you can remove the constructor and add the private no-args constructor. You will also need the static setSimulator () method, which sets the static field and will invoke it before any other interaction with the simulator is required.
If you have dependencies between singletones, I would recommend switching to the Inversion-of-Control pattern, where the IoC container creates the service objects and connects them together.
source share