Search code examples
javadesign-patternsfacademediator

Facade pattern - request flow


I know that Facade pattern is used to provide the simpler interface by hiding the complex subsystem interactions.

I am referring the below wikipedia uml on Facade pattern:

enter image description here

Are the communications/calls to the Facade are uni-directional requests i.e., only Client1/Client2 sends a request and receive the response from Facade, but the Facade can't initiate a request to Client1/Client2 ?

Am I correct in saying that Facade provides uni-directional (Client -> Facade) request interactions (by simpler interface) where as Mediator facilitates the bidirectional (Client <-> Mediator) interactions across the systems/classes ?

Can you provide a reference which stresses on this point ?


Solution

  • Yes, you are correct on both counts. Here is the pertinent quote, directly from the GoF book, page 282 (emphasis mine).

    Facade differs from Mediator in that it abstracts a subsystem of objects to provide a more convenient interface. Its protocol is unidirectional; that is, Facade objects make requests of the subsystem classes but not vice versa. In contrast, Mediator enables cooperative behavior that colleague objects don't or can't provide, and the protocol is multidirectional.

    Also note that Facade is classified as a structural pattern, whereas Mediator is a behavioral pattern. If a Facade could initiate requests, that would make it behavioral.