We have a Visual C++ 2013(C++11) solution in which we have multiple components. I would like to notify other components in the case of any change in any one component. Its not always that each component needs to know each change. What I mean is,
Lets say I have component A, B, D and D
There is a change in component A. Components B, C and D would need to know about the change in component A. There is a change in component B. Components A and C would need to know about the change in component B. There is a change in component C. Components A, B and D would need to know about the change in component B. There is a change in component D. Nobody needs to know.
For this, we have three ideas in mind and I would like to know what could be the best way to go, ofcourse anything other than these three ideas are more than welcome.
Idea 1:
- Components A, B, C and D have a method(function x) that can be invoked to let him know that a change has happened. Say if a change in component A happened, A would directly call function x of each of the other components that need to be informed.
Idea 2:
- Components A, B, C and D have a method(function x) that can be invoked to let him know that a change has happened. Each component publishes an event when a change happens in him. Other components register to components only if they are interested in them to receive messages about changes in the registered component. The component after receiving the message, processes it by calling his x method.
Idea 3:
- Components A, B, C and D have a method(function x) that can be invoked to let him know that a change has happened. Each component publishes an event when a change happens in him. The message reaches all components and the receiver decides if he needs to process the message based on the sender of the message, and so calls or not calls his x method.
The factors we are considering in the solution are,
- Performance
- Least complexity in implementation
- Ease of implementation
Aucun commentaire:
Enregistrer un commentaire