Mediator design pattern

C

Coder-X

Hi,

can someone give a real app example of where the Mediator design pattern
could be used ( for instance in a relational database application )?

Thanks,
José Carlos Ferreira
 
N

Nick Malik [Microsoft]

can someone give a real app example of where the Mediator design pattern
could be used ( for instance in a relational database application )?

Hello Jose,

That's an odd request. You don't often see the need for a mediator in a db
app. That said, I can come up with one.
Let's say that you have a distributed system. You have two data base
systems (with different data) and two web applications, on different web
servers. Therefore, four participants: db1, db2, wa1, and wa2. All four
fire up a mediator class when they start up. The mediator class handles all
the connection glue, figuring out how each one will talk with another over
the network, and how each will identify the other, and how each will know of
the others' existence.

Assuming we use a mechanism that allows us to set up a config file with
settings about how to communicate, then from within wa1, if I want to speak
with wa2, I could do this:

Mediator M1 = new Mediator();
M1.InitializeFromConfig(this, "wa1"); // read the config and identify
yourself
M1.SendTo("wa2",myObjectMessage);

Does that make sense? The app isn't aware of how the communication is
configured. That is all done by the mediator. I could be dropping files in
a file share, or sending data on a TCP port, or even using .Net Remoting.
The sending app simply sends the message. (if the sending app is expecting
to get a message back, it should probably hook an event from the mediator
object using delegates.

Hope this helps,
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top