Un-Mapping Mapped Network Drives Andrew Coates - dFPUG-Portal
Un-Mapping Mapped Network Drives Andrew Coates - dFPUG-Portal
Un-Mapping Mapped Network Drives Andrew Coates - dFPUG-Portal
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Best Practices FoxTalk<br />
Seeing Patterns: The Mediator<br />
Jefferey A. Donnici<br />
This month’s column continues the series that looks at some<br />
common design patterns and how they can be found and<br />
used within our Visual FoxPro applications. The pattern<br />
discussed this month is the Mediator pattern, which allows a<br />
single object to handle the interaction between a set of other<br />
objects. In doing so, the set of mediated objects is less<br />
coupled to one another and can be extended or varied<br />
independently. To illustrate the Mediator pattern in action,<br />
two very different examples are given.<br />
WITH the last Best Practices column, I began a new<br />
series called “Seeing Patterns.” For those who<br />
missed that column (for shame!), the intent<br />
behind this series is to discuss the real-world use of some<br />
common design patterns, using VFP examples for<br />
illustration. If you aren’t already familiar with the concept<br />
of object-oriented design patterns, I encourage you to<br />
look through the last column for some references and a<br />
discussion that provides an introduction to the ideas<br />
behind design patterns. Specifically, you should make<br />
sure to get a copy of Design Patterns: Elements of Reusable<br />
Object-Oriented Software by E. Gamma, R. Helm, R.<br />
Johnson, and J. Vlissides (Addison-Wesley, ISBN 0-201-<br />
63361-2). This is the most popular of all the patternsrelated<br />
books, and any developer working with an objectoriented<br />
language should have it.<br />
With the introduction to design patterns out of the<br />
way, I can dive right into this month’s discussion of the<br />
Mediator pattern. This column provides an introduction<br />
to the Mediator and, more importantly, some real-life VFP<br />
examples. Hopefully, the VFP-centric approach to this<br />
discussion will help you learn to “see” this pattern in<br />
your own work, thereby making it easier to pull it from<br />
your “toolbox” when solving a design problem in the<br />
future. Remember, however, that object-oriented design<br />
patterns represent another layer of abstraction above the<br />
design process. As such, the patterns themselves aren’t<br />
specific to any one programming language or design tool.<br />
Why the Mediator?<br />
The purpose of the Mediator pattern is to provide a<br />
central point for interaction between a set of similar<br />
objects. By having all interaction in a set of objects go<br />
through one portion of the component or subsystem, the<br />
dependencies and coupling between the objects in that set<br />
are reduced. As explained in Design Patterns, the intent of<br />
6 FoxTalk December 1998<br />
http://www.pinpub.com<br />
6.0<br />
the Mediator is to “define an object that encapsulates how<br />
a set of objects interact. Mediator promotes loose coupling<br />
by keeping objects from referring to each other explicitly,<br />
and it lets you vary their interaction accordingly.”<br />
A good object-oriented design typically has a large<br />
number of classes in it, simply because behavior and data<br />
are spread out among the classes to provide cohesion. The<br />
more a system is comprised of a set of highly specialized<br />
“pieces,” all working together to provide larger<br />
functionality, the more those pieces can be reused. On the<br />
extreme opposite end of the spectrum, a few large classes<br />
that perform several different functions apiece aren’t<br />
typically reusable in a different application context.<br />
The flip side of this design principle, however, is that<br />
the relationships between (or “the coupling of”) all those<br />
objects brings with it a higher learning curve for the<br />
designer and programmer, as well as the potential for<br />
reduced reusability. If each object in a subsystem must<br />
know the programmatic interface for all the other objects<br />
in the subsystem, then the overall reusability of every<br />
object suffers. So, while a large number of objects in a<br />
system typically means that they’re inherently more<br />
cohesive, each new object in the system has the potential<br />
to increase the number of dependencies exponentially.<br />
The Mediator provides a solution to this problem by<br />
acting as a central point of contact for all those intrasystem<br />
communications. Think of the Mediator as a<br />
“traffic cop” that makes sure everyone gets through the<br />
intersection like they should, without anybody having to<br />
get out of their car and talk to another driver. As long as<br />
all the “mediatees” (the cars and drivers) are being<br />
coordinated by the “mediator” (the traffic cop), there isn’t<br />
any need for the objects (or grumpy drivers) to interact<br />
with one another (see Figure 1).<br />
The benefits of this approach are numerous. The<br />
decoupling of the “mediatees,” called “colleagues” in<br />
Design Patterns, has been mentioned already, but there are<br />
others as well. For example, your class hierarchies can be<br />
less deep because the need to subclass is reduced when<br />
using a Mediator. The Mediator defines the interaction<br />
between the pieces of the system, so only the Mediator<br />
needs to be subclassed when the nature of the<br />
relationships changes. Each of the classes themselves<br />
remains the same, with the “translation” between them<br />
occurring within the Mediator.<br />
Also, the Mediator simplifies the nature of the