I have read multiple websites on this topic but none of them gave me a 'good' solution for the problem I am having. The problem is described in the following (related) questions:
- How do I couple the UI package with the rest of the system without too much coupling with classes inside the other packages (I am thinking of the facade pattern).
- I am having a lot of single instance classes but I don't want to use the Singleton Pattern to force the single instance. In some cases I need access to those classes in other packages.
See the figure below for a (simplified) class and package diagram of the system. I am having a class ProtocolParser (not the real name) that parses incoming data and raises events when certain packages are received. The events are handled by the AnchorManager and the TagManager. Those classes do almost the same thing. When the event is received they look in their list of Anchors or Tags if they find a Anchor or Tag with the same id they update it with new data otherwise they create a new Anchor or Tag. I also have class TrackingDeviceManager this class is responsible for keeping a list of all TrackingDevices in the system (so for example the UI can show a list of them).
It is not really useful to have multiple instances of the classes TrackingDeviceManger, AnchorManager and TagManager since they need to keep track of all the TrackingDevices, Anchors or Tags in the system. So I could potentially make them singletons. But I don't think the singleton pattern is the right way to go here.
So I am thinking to implement a TrackingFacade (singleton and a facade) this class will create instances of the three classes and initialize them. It also exposes some public methods and events so other classes in other packages can consume those. But I am wondering if this is a good approach. Or should I rethink my design?