- Object Interactions
- Object Interaction Scenario in IT Management
- Example of a Mediator
- Mediator Base Class
- Mediator Subclass
- Widget Class
- Two Widget Subclasses
- LspDirector Implementation
- Widget Class Implementation
- PathWidget Class Implementation
- Putting It All Together
- Conclusion
- Additional Reading
Putting It All Together
Listing 10 illustrates an expanded version of the main() function from Listing 1.
Listing 10 Mediator In Action
int _tmain(int argc, _TCHAR* argv[]) { LspDirector* anExampleMediator = new LspDirector(555); anExampleMediator->CreateWidgets(); anExampleMediator->ChangePath("R2R6R5"); anExampleMediator->ChangeQoSDetails("Expedited Forwarding"); delete anExampleMediator; return 0; }
Listing 10 does the following:
- Creates a mediator instance.
- Creates some widgets.
- Changes the widget configurations.
- Deletes the mediator.
Figure 2 illustrates the program output.
Figure 2 Program output
The first two lines of Figure 2 illustrate the path and QoS widgets being constructed and initialized. Figure 1 shows that the path R2R3R4R5 describes the route taken by LSP123. The QoS configuration is set to Assured Forwarding. The first two lines of Figure 2 occur as a result of executing the first two lines of Listing 10.
The third line in Figure 2 shows the path being modified to R2R6R5 (refer to Figure 1 for this new path). This line occurs as a result of executing the third line in Listing 10. In Figure 2 (line 4), you can see that the mediator (or director) has been informed of the change.
Then, the QoS setting is modified in exactly the same way with similar results.