Java Reference
In-Depth Information
When you have an object model that is not tied to a relational database, you can use mediators
to sustain the relational integrity of your model. Move the logic that gets and sets relations
between objects into mediator classes. Such classes can specialize in maintaining relational
integrity and can apply tablelike data structures that naturally guarantee integrity.
CHALLENGE 10.5
With respect to factoring logic out of a class, M EDIATOR is similar to other patterns.
List two patterns that may involve moving an aspect of behavior out of an existing
class or hierarchy.
Summary
The M EDIATOR pattern promotes loose coupling, keeping related objects from referring to
one another explicitly. M EDIATOR shows up most often in GUI application development, in
which you don't want to manage the complexity of individual widgets' updating one another.
The architecture of Swing guides you in this direction, encouraging you to define objects that
register for GUI events. If you are developing with Swing, you are probably applying
M EDIATOR .
Swing nudges you into using M EDIATOR , but Swing does not force you to move this
mediation outside an application class. Doing so can simplify your code. You can let
a mediator class concentrate on the interaction between objects and let an application class
concentrate on component construction.
There are other cases in which you can benefit from introducing a mediator object. For
example, you might need a mediator to centralize responsibility for maintaining the relational
integrity in an object model. You can apply M EDIATOR whenever you need to define
an object that encapsulates how a set of objects interact.
Search WWH ::




Custom Search