Suppose you were building a system that receives data on one end and sends filtered data on the other end.
The system is a chain of nodes, each receiving data from the node before and sending filtered data to the next one.
You have two approaches to choose from regarding the way the nodes would be connected:
A- Each node holds a reference to the next one through a particular interface.
B- Each node exposes an event, and the next node in line would be registered to that event, notified when that event is fired (when the previous node in line sends data).
In both cases, an outside entity connects the nodes to one another; they have no direct knowledge of each other.
Currently, I think events may be better because this way, a node doesn't care what the next node does; only what it has to send it. Thus enabling us to insert nodes in the middle easily.
There is a possibility nodes would need to be inserted in the middle, in the future.
Taking that into account, which approach would you prefer, and why? What are the pros and cons of each approach?