- 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
PathWidget Class Implementation
Listing 9 illustrates the implementation in all its glory! Notice that the constructor calls the base class constructor, which shows the magic of object orientation! The base class object then maintains the pointer to the mediator, which reduces the level of clutter in the subclasses. The CreateInitialPath() method is used to create an initial configuration for the PathWidget instance. To retrieve the configuration, we use the getNewPath() method. To change the configuration, we use the ChangePath() method.
Listing 9 PathWidget Implementation Code
PathWidget::PathWidget(ConnectionDirector* theDirector) : Widget(theDirector) { } PathWidget::~PathWidget(void) { } void PathWidget::CreateInitialPath(char* newPath) { pathDetails = newPath; printf("Initial path setting: %s\n", pathDetails); } void PathWidget::getNewPath(void) { printf("The PathWidget path is: %s\n", pathDetails); } void PathWidget::ChangePath(char* newPath) { pathDetails = newPath; printf("The updated PathWidget path is: %s\n", pathDetails); Changed(); }
The semantics for the other widget subclass are almost identical, so I won’t list them here. Let’s now see how all this code works when we run the program.