Difference between Facade and Mediator Design pattern?

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

    I have confusion in following code segment which looks similar in both the design patterns.

    I think you're seeing the composition aspects of both patterns.

    Facade links to various existing classes of a subsystem to add some typical functionality that simplifies use of the subsystem. In the example code you cited, ShapeMaker provides services that facilitate making shapes.

    Mediator links to various colleagues that have to collaborate, so as to minimize the knowledge the colleagues have about each other. Minimizing knowledge has the side effect of reducing coupling between colleagues (they only know the mediator) and increasing their cohesion (they generally have less to worry about since they don't know about the bigger picture).

    In both patterns, the centralized class assumes responsibility for the complexity of dealing with the classes it is linked to.

    Here are the basic patterns in UML from the Gang of Four:

    Facade pattern

    Mediator pattern

提交回复
热议问题