Difference between Facade and Mediator Design pattern?

前端 未结 4 1896
鱼传尺愫
鱼传尺愫 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:33

    The facade exposes existing functionality and the mediator adds to the existing functionality.

    If you look at the facade example, you will see that you are not adding any new functionality, just giving the current objects a new perspective. For example, Circle already exists and you are just abstracting off circle, using the method drawCircle.

    If you look at your mediator class, you see that the method handle() provides additional functionality by checking the state. If you were to take out the conditions, you would have a facade pattern, since the additional functionality is gone.

提交回复
热议问题