The course is part of this learning path
This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.
Learning Objectives
- Understand what design patterns are
- Learn about the myriad of design patterns that you can use in your projects
Intended Audience
This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.
Prerequisites
Basic knowledge of Java programming.
Hello, dear friends. In this video, we will examine our last structural pattern known as facade. Let's begin. Facade is a part of Gang of Four design pattern and it is categorized under structural design patterns. Facade means the face of a building. While passing across a 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.urlclass 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 appropriate 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 in 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. Let's create a project and apply the face pattern. Create a new project and name it Facade. I'd like to create a game selection project for football, basketball, or handball.
First, we need an interface. Let's name it Sport. Now we need a method. Let's name it setGame() ;. Let's define our sport types. Class Football implements Sport{. Override method. Football has been chosen. Let's go on with basketball. Override method with basketball. Last one is handball. Done. Now we need a tournament class to use these sports. First, let's define our properties as sport types from Sport interface. Now, we need constructor. In constructor, we will set sports to interfaces. Let's add methods. SetFootball( ). Basketball( ). Handball( ). Done. Now we can use this structure in Client page. First, we need a tournament instance. Let's call set methods one-by-one. Done. When we run project, as you see, the result is football, basketball, and handball. Now, with the facade pattern, we have finished looking at the structural patterns. In the next video, we will start to examine behavioral patterns, starting with the chain of responsibility pattern. See you in the next video.
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.