Mediator design pattern

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Coder-X

    #1

    Mediator design pattern

    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


  • Nick Malik [Microsoft]

    #2
    Re: Mediator design pattern

    > can someone give a real app example of where the Mediator design pattern[color=blue]
    > could be used ( for instance in a relational database application )?[/color]

    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.InitializeFr omConfig(this, "wa1"); // read the config and identify
    yourself
    M1.SendTo("wa2" ,myObjectMessag e);

    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.
    --


    Comment

    Working...