Façade vs. Mediator

后端 未结 8 1392
粉色の甜心
粉色の甜心 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.

提交回复
热议问题