
What
is the need for Mediator Pattern
|
public class
mediatorClass {
private derivedClass1 obj1;
private derivedClass2 obj2;
public derivedClass1 Obj1 {
set { obj1 = value; }
}
public derivedClass2 Obj2 {
set { obj2 = value; }
}
public void sendMessage(string msg, baseClass obj) {
if(obj == obj1) {
obj2.notifyCommunication(msg);
}
else if(obj == obj2) {
obj1.notifyCommunication(msg);
}
}
}
This is just
a partial code snippet. Your program should also include an abstract class
called baseClass that contains mediatorClass instance as its member. This
baseClass is inherited by two classes namely derivedClass1 and derivedClass2.
In mediatorClass, you create instances of these two derived classes and
achieve communication among them using the sendMessage method. Note that
your derived classes should implement the method notifyCommunication.
_______________________________________________________________________
FREE Subscription
Subscribe
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
Note
: We never rent, trade, or sell my email lists to
anyone.
We assure that your privacy is respected
and protected.
Visit .NET Programming Tutorial Homepage
______________________________________________________