Difference between Facade and Mediator Design pattern?

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

    The Facade pattern key notes:

    1. A simple interface is required to access a complex system.
    2. The abstractions and implementations of a subsystem are tightly coupled.
    3. Need an entry point to each level of layered software.
    4. System is very complex or difficult to understand.

    Related post:

    What is Facade Design Pattern?

    Mediator pattern key notes ( dzone article) :

    1. Mediator pattern is useful when the communication logic between objects is complex, we can have a central point of communication that takes care of communication logic.

    2. We should not use mediator pattern just to achieve lose-coupling because if the number of mediators will grow, then it will become hard to maintain them

    Structure:

    The Mediator defines the interface for communication between Colleague objects.

    The ConcreteMediator implements the Mediator interface and coordinates communication between Colleague objects.

    It is aware of all the Colleagues and their purpose with regards to inter communication.The ConcreteColleague communicates with other colleagues through the mediator.

    Regarding your query:

    1. Your first example represents Facade pattern. ShapeMaker is entry point to complex system, which consists of various Shape sub-systems.

    2. Your second example does not represent Mediator pattern in true sense. The interactions have been hard-coded. You have to define interfaces and program to those interfaces. Refer to above dzone article for better understanding of Mediator example.

提交回复
热议问题