Facade Design Pattern
Start course
3h 59m

In this course, we will learn the concepts of microservice and spring framework with a focus on design patterns.

Learning Objectives

  • Learn about various design patterns

Intended Audience

  • Beginner Java developers
  • Java developers interested in learning how to Build and Deploy RESTful Web Services
  • Java Developers who want to develop web applications using the Spring framework
  • Java Developers who want to develop web applications with microservices
  • Java Developers who wish to develop Spring Boot Microservices with Spring Cloud


  • Basic Java knowledge

Hello, dear friends. In this video, we will examine our last structural pattern known as Facade. So, let's begin. Facade is a part of Gang of Four Design Pattern and is categorized under structural design patterns. Facade means the face of a building. While passing across the street, all we look at is the face of a building. The face abstracts all the complex implementation details of a building. Similarly, a Facade Design Pattern aims to provide a unified interface to a set of interfaces in the subsystem. 

This unified interface hides the subsystem complexity from the client. It falls under the category of structural patterns. The java.util connection in Java is a facade as it allows us to create DB connections and hides the implementation details. Similarly, java.net URL class is another Facade that exposes the open stream method hiding all involved details. The Facade pattern is usually a Refactoring pattern. For a large complex subsystem, it's a fairly good idea to use a Facade pattern and provide the clients with a friendly interface to interact with. The Facade pattern is an appropriate way when we have a complex system that we want to expose to clients in a simplified way.

Its purpose is to hide internal complexity behind a single interface that appears simple from the outside. Facade also decouples the code that uses the system from the details of the subsystems, making it easier to modify the system later. Basically, Facade allows us to use the open-closed principle and solid. The Facade pattern describes a higher level interface that makes the subsystems easier to use. Practically, every abstract factory is a type of Facade. So, let's create a project and apply the Facade pattern. Create a new project and name it Facade. I'd like to create a game selection project for football, basketball or handball. So, first, we need an interface. Let's name it Sport. Now, we need a method. Let's name it setGame. Let's define our sports type. Class Football implements Sport; override method. "Football has been chosen."

Let's go on with Basketball. Override method with Basketball. Last one is Handball. Okay, done. Now, we need a tournament class to use these sports. First, let's define our properties as sports types from sport interface. Now, we need a constructor. In constructor, we will set sports to interfaces. Okay, let's add methods: setFootball, setBasketball, setHandball. Okay, done. Now, we can use this structure in client page. First, we need a tournament instance. Let's call set methods one by one. Okay, done. When we run project, okay, as you can see, the result is Football, Basketball, and Handball is selected. Now, that we've gone over the Facade pattern, we have finished looking at the structural patterns. Hooray. So, in the next video, we will start to examine behavioral patterns starting with the chain-of-responsibility pattern. So, I'll see you in the next video my friends.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.