Difference between Facade and Mediator Design pattern?

前端 未结 4 1895
鱼传尺愫
鱼传尺愫 2021-01-14 05:19

What is the difference between facade and mediator design pattern. I want understand which design pattern to choose between these two in which scenario. I was going through

4条回答
  •  广开言路
    2021-01-14 05:49

    The facade pattern gives you a simple interface which interacts on a set of coherent classes. For example a remote control for your house which controls all kind of equipment in your house would be a facade. You just interact with the remote control, and the remote control figures out which device should respond and what signal to send.

    The mediator pattern takes cares of communication between two objects, without the two objects need to have a reference to each other directly. A real life example is sending a letter, you post your letter and the postal service picks it up and makes sure that it will be delivered at the recipient. Without you telling them what route they should take. That is the mediator does.

    Your examples however sound more like a creational pattern (looks like a factory) and a behavioral pattern (state pattern). I understand your confusion.

提交回复
热议问题