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.
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.
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database