For the complete documentation index, see llms.txt. This page is also available as Markdown.

Facade Pattern

The Facade Pattern is a structural design pattern that provides a simple interface to a complex system.

Instead of interacting with multiple classes directly, the client communicates with a single facade class.


Real Life Example

Think about an Online Food Order App 🍔

To place an order internally, the system may:

  1. Validate payment

  2. Check restaurant availability

  3. Assign delivery rider

  4. Generate invoice

  5. Send notification

But the customer only clicks:

Place Order

The app hides all complexities behind one simple interface.

This is the Facade Pattern.


Structure


Laravel / PHP Example

Scenario

We are building an eCommerce order system.

Complex subsystems:

  • Payment Service

  • Inventory Service

  • Shipping Service

  • Notification Service

We simplify everything using a facade.


Step 1: Subsystem Classes

Payment Service


Inventory Service


Shipping Service


Notification Service


Step 2: Create Facade Class


Step 3: Usage


Output


Without Facade

Client must handle everything manually:

Too much complexity.


With Facade

Simple and clean.


Advantages

1. Simplifies Complex Systems

One interface for multiple services.


2. Reduces Coupling

Client does not depend on subsystem details.


3. Cleaner Code

Improves readability and maintainability.


4. Easy Integration

Useful for:

  • APIs

  • Third-party libraries

  • Large systems


Real Laravel Example

Laravel itself heavily uses the Facade Pattern.

Examples:

Laravel Facade
Underlying Service

Cache::get()

Cache Manager

DB::table()

Database Manager

Mail::send()

Mail Service

Auth::user()

Authentication Service


Example

Behind the scenes, Laravel resolves multiple internal classes.

That is Facade Pattern.


Facade vs Adapter

Facade
Adapter

Simplifies complex system

Converts one interface to another

Focus on usability

Focus on compatibility

Provides unified interface

Makes incompatible classes work together


Facade vs Decorator

Facade
Decorator

Simplifies access

Adds behavior

Hides complexity

Enhances object

Structural simplification

Functional enhancement


When to Use Facade Pattern

Use Facade when:

✅ System is complex ✅ Multiple subsystems exist ✅ You want cleaner APIs ✅ You want to reduce client dependency


Short Interview Definition

The Facade Pattern provides a simplified unified interface to a complex subsystem.

Last updated