Back to Advanced Patterns & Architecture
Q2Question 2 of 5

Explain the Facade design pattern with use cases

Key Concepts
  • A facade provides one simple, higher-level interface to a complex subsystem of many classes.
  • The facade coordinates and delegates to subsystem classes; it does not add business logic of its own.
  • Clients depend on the stable facade interface, not on volatile subsystem internals, reducing coupling.
  • The facade does not forbid direct access; advanced callers can still use subsystem classes.
  • An API Gateway in microservices is essentially a facade at the network level.
  • Keep the facade thin; if it holds real rules it becomes a God object violating single responsibility.
  • The facade is an excellent place for a single transaction boundary and consistent logging.

Definition

A facade is one simple front door that coordinates a complicated subsystem behind it, so clients call one easy method instead of wiring together many classes themselves.
  • Facade – a structural design pattern that provides a single, simplified, higher-level interface to a complex subsystem of many classes.
  • Delegation – the facade holds references to subsystem classes and calls them in the correct order; it adds no business logic of its own.
  • Reduced coupling – clients depend only on the facade's stable interface, not on the volatile internals of the subsystem.
  • Non-intrusive – the facade offers the easy path for common cases; advanced callers can still use subsystem classes directly.
  • Thin coordinator – if the facade starts holding real rules, it degrades into a God object.

Imagine Rajesh wants a home loan from National Bank of India. Behind the scenes a home loan involves credit-score checks, income verification, property valuation, legal title checks, and disbursement. Rajesh does not want to visit five departments. Instead he goes to one Loan Relationship Manager who coordinates all five departments and comes back with a decision. That relationship manager is the facade: one simple front person hiding a complicated process.

Understanding the Concepts

What is the Facade pattern?

A subsystem often grows into many collaborating classes, each doing part of a workflow. If every client has to know all those classes and the right sequence, the client becomes tightly coupled to the subsystem. The facade solves this by exposing a small number of coarse-grained methods that represent what clients actually want to do.

How does delegation work inside a facade?

The facade holds references to subsystem classes and calls them in the correct order.

JAVA
package com.bank.facade;

import com.bank.service.CreditScoreService;
import com.bank.service.IncomeVerificationService;
import com.bank.service.PropertyValuationService;
import com.bank.service.LegalTitleService;
import com.bank.service.DisbursementService;
import java.math.BigDecimal;

public class LoanApprovalFacade {

    private final CreditScoreService creditScore;
    private final IncomeVerificationService income;
    private final PropertyValuationService property;
    private final LegalTitleService legal;
    private final DisbursementService disbursement;

    public LoanApprovalFacade(CreditScoreService creditScore,
                              IncomeVerificationService income,
                              PropertyValuationService property,
                              LegalTitleService legal,
                              DisbursementService disbursement) {
        this.creditScore = creditScore;
        this.income = income;
        this.property = property;
        this.legal = legal;
        this.disbursement = disbursement;
    }

    public LoanDecision approveHomeLoan(String customerId, BigDecimal amount) {
        int score = creditScore.fetch(customerId);
        if (score < 700) return LoanDecision.rejected("Credit score below 700");

        boolean incomeOk = income.verify(customerId, amount);
        if (!incomeOk) return LoanDecision.rejected("Income insufficient");

        BigDecimal valuation = property.valuate(customerId);
        boolean titleClear = legal.checkTitle(customerId);
        if (!titleClear) return LoanDecision.rejected("Title not clear");

        disbursement.disburse(customerId, amount);
        return LoanDecision.approved(amount, valuation);
    }
}
TEXT
Expected output:
LoanApprovalFacade: approveHomeLoan(CUST-1001, 5000000.00)
CreditScoreService: score=750
IncomeVerificationService: verified=true
PropertyValuationService: value=7500000.00
LegalTitleService: clear=true
DisbursementService: disbursed 5000000.00
Result: APPROVED

How is the Facade different from Adapter, Mediator, and Proxy?

| Pattern | Purpose | Direction |
|---|---|---|
| Facade | Simplifies a complex subsystem into one interface | One-way; subsystem does not know the facade |
| Adapter | Converts one interface to another so incompatible things fit | Wraps one object |
| Mediator | Coordinates two-way interaction between peers | Bidirectional; peers talk back to mediator |
| Proxy | Stands in for one object to control access, caching, laziness | Wraps one object, same interface |

Why must the facade stay thin?

If the facade starts holding real business rules it becomes a God object violating single responsibility. The real logic stays in the subsystem classes; the facade only orchestrates.

JAVA
// WRONG: facade holds business logic
public LoanDecision approve(String customerId, BigDecimal amount) {
    // calculating EMI, applying interest rates, checking blacklists HERE
    // turns the facade into a God object
}

// CORRECT: facade delegates to specialists
public LoanDecision approve(String customerId, BigDecimal amount) {
    if (creditScore.fetch(customerId) < 700) return rejected();
    // each specialist holds its own logic
}

What are typical use cases?

  • A @Service class in Spring that orchestrates repositories, validators, and external clients to fulfil one business operation.
  • Wrapping a complicated third-party library so the rest of the code calls a simple in-house interface.
  • One onboardCustomer or processLoan method that coordinates many steps.
  • An API Gateway presenting one endpoint that fans out to many internal services.

How does a facade relate to microservices?

At the network level, an API Gateway is essentially a facade: it presents one entry point, coordinates calls to multiple backend services, and hides the internal topology from clients.

What should a senior engineer know?

  • The facade is an excellent place to apply a single transaction boundary, consistent logging, and uniform error translation for a whole workflow.
  • You can have several facades over the same subsystem for different client needs.
  • The pattern shines when onboarding new developers, who can accomplish common tasks through the facade without learning the entire subsystem.
  • In Spring, constructor injection makes the delegation explicit and testable.

What are common interview follow-up questions?

  • Can a facade call another facade? (Yes, but keep the depth shallow to avoid hidden complexity.)
  • How do you test a facade? (Unit test with mocked subsystem classes; integration test the full chain.)
  • When should you NOT use a facade? (When there is no subsystem complexity to hide; adding a facade around one class is pointless indirection.)

Visual Overview

DIAGRAM
  Facade Pattern

  ┌───────────────────────────────────────────┐
  │            LoanApprovalFacade             │
  │  approveHomeLoan(customerId, amount)      │
  └──┬───────┬───────┬───────┬───────┬───────┘
     │       │       │       │       │
     ▼       ▼       ▼       ▼       ▼
  ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
  │Credit│ │Income│ │Prop. │ │Legal │ │Disb. │
  │Score │ │Verif.│ │Value │ │Title │ │      │
  └──────┘ └──────┘ └──────┘ └──────┘ └──────┘
    Subsystem classes (hold the real logic)

  Client → Facade → Subsystem (client never touches subsystem directly)

  API Gateway as a Network-Level Facade
  ┌──────────┐     ┌───────────┐
  │  Mobile  │────►│   API     │────► Transfer Service
  │  Client  │     │  Gateway  │────► Account Service
  └──────────┘     │ (Facade)  │────► Fraud Service
                   └───────────┘

Key Takeaway

The Facade is a structural pattern that gives clients one simple, higher-level interface to a complex subsystem of many classes. The facade does not add business logic of its own; it coordinates and delegates to the subsystem in the correct order, so clients depend on one easy entry point instead of on many moving parts. That reduces coupling, makes common workflows trivial to call, and lets the subsystem evolve internally as long as the facade's interface stays stable.

At National Bank of India, Pankaj introduced a LoanApprovalFacade with one method that runs five subsystems in the correct order and returns a single decision. When the bank later replaced its in-house credit scorer with an external bureau, they changed only the facade's wiring and not a single caller, because everyone depended on the facade's stable interface.

The key discipline is keeping the facade thin. The moment it starts holding real rules it degrades into a God object. The real logic stays in the subsystem classes; the facade only orchestrates. And the facade is non-intrusive: it offers the easy path for common cases, but advanced callers can still use subsystem classes directly.

Remember one sentence: a facade is one simple front door that orchestrates a complicated subsystem behind it, reducing coupling and making common tasks easy, while the key discipline is keeping it thin so it coordinates without becoming a God object.

---

Share
Use ← → arrow keys to navigate