- 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
Widget Class Implementation
Listing 8 illustrates the Widget base class implementation.
Listing 8 Widget Implementation Code
Widget::Widget(ConnectionDirector* aConnDirector) { _director = aConnDirector; } void Widget::Changed(void) { _director->WidgetChanged(this); }
The constructor for Widget is passed a pointer to an instance of ConnectionDirector. This pointer is stored in the data member _director. Remember that the widgets tell the mediator about changes applied to them? Well, the Changed() member function serves this purpose. You’ll soon see how this is done when we look at the PathWidget implementation.