The Traditional Approach versus Event-Driven Programming
As we mentioned in the introduction, in traditional programming patterns, we like to have a direct link between our components when we want them to communicate. This is shown in the following diagram:
Figure 9.1: Traditional programming approach
For a simple application that allows the user to update their profile and receive messages, we can see that we have four components:
- Agent
- Profile
- Votes
- Messages
The way these components interact with each other is by calling the appropriate methods in the component that wishes to communicate. By doing this, it makes the code very easy to understand, but we might have to pass the component reference over. Take our Agent
class, for example:
class Agent { Â Â Â Â constructor(id, agentInfo, voteObj, messageObj) { Â Â Â Â Â Â Â Â this.voteObj = voteObj; Â Â Â Â Â Â ...