mardi 13 avril 2021

Scalable architecture design for managing data flow in C++ using an Observer design pattern

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:

Callback Sequence

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:

UML Design

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:

New data flow Sequence

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