I have several “widgets” involved in a presentation that need to interact with each other, but the interactions have gotten complex enough to warrant a new object to handle the interactions.
In trying to work through a Mediator as that object, I am confused as how to construct the participants effectively. The mediator has to know about the widgets, and the widgets have to know about the mediator.
Using the toy classes below can someone show me how the constructors would look and in what order they would typically be created?
Cheers,
Berryl
class WidgetOne {
Mediator _mediator;
}
class WidgetTwo {
Mediator _mediator;
}
class Mediator {
WidgetOne _widgetOne;
WidgetTwo _widgetTwo;
}
That really depends on a number of other circumstances, but I would probably do this:
Of course, if nothing else needs to know about the widgets, then I would get rid of the setters and just have this:
A couple of others in brief… brief form: