Facade Design Pattern

Learn about the facade pattern, its applicability, and its purpose.

Overview

Suppose that we’ve written code for an application with many classes. If we develop a large-scale system while following the single responsibility and loose coupling principles, our code will likely have many classes.

But there’s one problem. Any client (a piece of code) that interacts with the system will have to interact with a lot of classes, and sometimes that can become messy. How do we handle this situation?

The facade pattern is used to solve this problem. In the facade pattern, we have an extra class through which the client accesses the code (which has a lot of classes). This way, the client won’t need to interact with the classes directly. It makes our code look cleaner and is easier to understand. Don’t worry if this sounds confusing. We’ll discuss an example in the upcoming lesson, which will define the concept more clearly.

Type

The facade is a Gang of Four design pattern that falls under structural design patterns.

Purpose

The facade pattern hides the system’s complexities and provides a simpler interface for the client to access the code (system).

Applicability

Facade makes the client’s interaction with classes easy. A facade pattern is applicable where the client is satisfied with a simple view of the complex system provided by the facade. Only those clients that want to interact with classes directly and want greater customization will have to look beyond the facade pattern.

Structure

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy