• Post Reply Bookmark Topic Watch Topic
  • New Topic

Design Pattern Facade  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I'm starting to read the book Design Patterns in Java but do not quite understand the Facade pattern,
someone could help me with a little more information about this pattern, they are appreciated.
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way to think of the Facade pattern is as a wrapping of a complex or multi-step process into a simpler to use interface.

Let's say I have a library which moves the mouse around the screen. It might have classes / methods which look like this:


And you could then use that interface to simulate a drag-and-drop process:


That isn't too bad, and since you know the users of your library will use it a lot, you could publish the snippet somewhere as a recipe. Or, you could write a Facade that makes the process easier for the end user:


Then when it comes time to use your library to drag something on screen, you can replace the 14 lines of code in the drag sample above with this:


The Facade here doesn't add anything new to the scenario, it just wraps current functionality in a way easier to digest and figure out. It would make your code easier to interface with, and cause less bugs in the applications which use your library.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!