Facade Pattern in Java

This pattern, reminds me of this Joke:

Artificial Neural Networks is like teenage sex.
Everyone talks about it.
Nobody really knows how to do it.
Everyone thinks everyone else is doing it.
So everyone claims they are doing it… 😝

These days we have a lot of ANN libraries. If you see the JavaScript library Synaptic, they have black-boxed the complex part of the system. They provide some simple public functions to implement ANN in your project.

The term facade means the principal front of a building, that faces on to a street or open space.

Facade of a building

Apparently, you are dealing with the UI part, rather than seeing the inside plumbing, wiring etc of a house.

Examples:

Retrofit gives simple methods to play with REST API’s
  • The network library Retorfit black boxes, the complex system, and provides simple functions for API handling.
  • Encryption Libraries, also black boxes, the complex encryption and provides simple ways to hash, encrypt files.

Social understanding

Typically, if there is a complex part (for eg:- ML or CV) in your project, the person knowledgeable at this, could create a Facade, so that, other people could work using it (and do productive things like UI/X etc), rather than spending time, understanding the complex part. We can avoid the complex wiring.

Rotate Cube Example:

The example provided is not complete, but enough to get an overall understanding. This example reminds me of the Juspay Hiring Challenge, when I was supposed to create a rotating cube (I couldn’t complete it btw).

Project Structure:

Implementation in Java

  1. Lets start creating the inner wiring (plumbing).

Point.java

Line.java

Cube.java

2. Create a Driver to implement the facade.

Found it Interesting?
Please show your support by 👏. To read the complete series, click below.

Disclaimer:
I myself, has just started learning, design patterns. If you find any issues please feel free to post them in the comments section below. Thank you for reading so far 😄

Writes on Big Data, AWS & Backend technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store