Facade Pattern



Facade is a structural design pattern that provides a simplified interface to a complex set of classes. The client makes all the requests to a single class - the Facade - which delegates these methods to other existing classes in the subsystem. The client does not need to know the classes in the subsystem.



Design principles (link):

  • (OK) Single Responsibility Principle - the Facade is only an intermediary between the client and the subsystem. If the Facade becomes too complex, with unrelated methods, additional Facades can be made to split these methods.
  • (NOK) Open Closed Principle - The Facade pattern violates the OCP since any time there is a new functionality a new method must be created in the Facade, otherwise the client cannot use it.

Relations with Other Patterns

  • Facade simplifies existing interface, normally wrapping a whole subsystem. Adapter adapts existing interface, wrapping only one class.
  • A Facade class can be transformed into a Singleton since a single facade object is often sufficient.

Comments

Popular Posts