facade - Harsh4999/Design-Patterns GitHub Wiki

Facade

Use

  • It tries to reduce the coupling between classes and interfaces in our subsystem code
  • It provides a simple and unified interface to a subsystem and hence client can directly interact with only one facade and it doesn't need to search for more classes and interfaces
  • Its not just one to one method forwarding

Uml

  • Subsystem = It may comprise of multiple packages,interfaces,classes etc which provide a specific functionality
  • Facade = It provides simple method definition and it interacts with subsystem to satisfy client request

Implementation

  • Its of great use on already written code
  • Facade will be a class
  • It should be readily usable and should expose ready to use methods to the client.
  • Its useful to avoid tight coupling on client side
  • It should minimize the complexity of using subsystem
  • Facade can be interface or abstract class and client can use different subclasses to talk
  • Eg: URL class