What I need
I need a suitable and scalable solution to manage data flow between the classes in my C++ program.
Why I need it
Upon new feature requests, I'm continually adding new classes to the program. I initially registered callback functions to classes and injected a dependency to the class via an interface:
Now, as the program scales, this is becoming quite difficult to maintain and keep track of where and when my data is flowing between class instances.
My Proposed solution
I've now redesigned the system to use an Observer pattern. I have a central event hub (Observable) to which I can subscribe my various services (Observers) to:
Note: I've also implemented this as an example on OneCompiler and the code is also available as a gist.
I can also pass the event hub to the classes if they will also need to push notifications.
The new data flow will now be:
What I want to know
Before I embark on a refactoring mission I would like to know:
- Is the observer pattern as I've implemented it in the example, a scalable solution to manage the data flow between my classes?
- If not, what is a better alternative to ensure I can pass data between different sections of my program on an event-driven basis?
Thanks in advance for the help.
Aucun commentaire:
Enregistrer un commentaire