- 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
Two Widget Subclasses
Listing 5 illustrates the PathWidget subclass derived from the Widget class.
Listing 5 PathWidget Subclass
class PathWidget : public Widget { public: explicit PathWidget(ConnectionDirector*); virtual ~PathWidget(void); void CreateInitialPath(char*); void getNewPath(void); void ChangePath(char*); private: char* pathDetails; };
We’re now moving into the application domain described in Figure 1! The PathWidget class stores its configuration data in the private data member pathDetails. This configuration data takes the form of a character string describing the path taken by an LSP in Figure 1.
Three member functions allow for manipulation of the configuration data:
- CreateInitialPath() is called at construction time to provide an initial value for pathDetails.
- getNewPath() is used to retrieve a modified version of pathDetails.
- ChangePath() is used to change the value of pathDetails.
Listing 6 illustrates the QosWidget subclass.
Listing 6 QosWidget Subclass
class QosWidget : public Widget { public: explicit QosWidget(ConnectionDirector*); virtual ~QosWidget(void); void CreateInitialQoS(char*); void getNewQoS(void); void ChangeQoSDetails(char*); private: char* QoSDetails; };
The QosWidget subclass is very similar to the PathWidget subclass. In fact, they’re so similar that there’s a case for trying to move some of their content into the base class. I’ll leave this as an exercise for the reader! An example of this is the _director data member in Listing 4, which is used by the subclasses.
You’ve seen the interface files; now let’s look at some of the implementation code.