Façade vs. Mediator

后端 未结 8 1389
粉色の甜心
粉色の甜心 2020-12-07 08:46

I\'ve been researching the difference between these two patterns.

I understand that facade encapsulates access to a sub system and mediator encapsulates the interac

相关标签:
8条回答
  • 2020-12-07 09:31

    I'm using mediator to add log file functionality.

    It works like this:

    • Obj A tells the mediator it needs something done.
    • The mediator sends the message to various client objects.
    • Obj B does the thing Obj A needs, and sends an appropriate message back via the mediator.
    • Meanwhile, Obj C is also sent both messages by the mediator, and logs the results. That way, we can get user statistics from the log files.
    • Obj D could be an error checker as well, so that if Obj B responds that Obj A's request is impossible, Obj D could be the thing that reports that to the user. Errors can now be logged in a different file than regular activity, and could use some other means to behave (beeping, whatever) that Obj A shouldn't really concern itself with.
    0 讨论(0)
  • 2020-12-07 09:34

    From the "Design Patterns" book, the KEY of the Mediator pattern is described as follows: "It (a mediator) acts as a HUB of communication for widgets (i.e., 'a' group of interdependent objects)."

    In other words, a mediator object is the sole superobject that knows all other objects in a group of collaborating objects and how they should interact with each other. All other objects should interact with the mediator object, instead of each other.

    In contrast, a facade is a "unified interface" for a set of interfaces in a subsystem - for use by consumers of the subsystem - not among the components of the subsystem.

    0 讨论(0)
提交回复
热议问题