Facade vs Strategy design pattern differences
While Facade and Strategy patterns are both design patterns, they are not the same. Let’s break it down clearly.
1️⃣ Facade Pattern
Purpose
- Provides a simplified interface to a complex subsystem.
- Makes it easier for clients to interact with multiple classes without knowing the details.
Key Idea
“Hide complexity behind a simple interface.”
Example
Imagine a home theater system:
class Amplifier { void on() {} void setVolume(int v) {} }
class DVDPlayer { void on() {} void play(String movie) {} }
class Projector { void on() {} void wideScreenMode() {} }
class HomeTheaterFacade {
private Amplifier amp;
private DVDPlayer dvd;
private Projector projector;
public HomeTheaterFacade(Amplifier a, DVDPlayer d, Projector p) {
amp = a; dvd = d; projector = p;
}
public void watchMovie(String movie) {
amp.on(); amp.setVolume(5);
projector.on(); projector.wideScreenMode();
dvd.on(); dvd.play(movie);
}
}
✅ Client code:
HomeTheaterFacade theater = new HomeTheaterFacade(amp, dvd, projector);
theater.watchMovie("Inception"); // one simple call
Key point: Client doesn’t need to know all the steps — Facade simplifies.
2️⃣ Strategy Pattern
Purpose
- Defines a family of interchangeable algorithms and makes them pluggable at runtime.
- Lets the client choose the behavior dynamically.
Key Idea
“Encapsulate interchangeable behavior and make it swappable.”
Example
Payment processing:
interface PaymentStrategy {
void pay(int amount);
}
class CreditCardPayment implements PaymentStrategy {
public void pay(int amount) { System.out.println("Paid " + amount + " with credit card"); }
}
class PayPalPayment implements PaymentStrategy {
public void pay(int amount) { System.out.println("Paid " + amount + " via PayPal"); }
}
class ShoppingCart {
private PaymentStrategy paymentStrategy;
public ShoppingCart(PaymentStrategy ps) { paymentStrategy = ps; }
public void checkout(int amount) { paymentStrategy.pay(amount); }
}
✅ Client code:
ShoppingCart cart = new ShoppingCart(new PayPalPayment());
cart.checkout(100); // Pays via PayPal
Key point: You can switch the strategy (CreditCardPayment, PayPalPayment) at runtime.
3️⃣ Facade vs Strategy – Side by Side
| Feature | Facade | Strategy |
|---|---|---|
| Intent | Simplify interface to a subsystem | Encapsulate interchangeable behaviors/algorithms |
| Client awareness | Hides complexity | Chooses behavior dynamically |
| Example | HomeTheaterFacade | PaymentStrategy (PayPal/CreditCard) |
| Number of variations | Usually single facade | Multiple strategies |
| Change at runtime | Not needed | Yes, dynamic swapping |
Published on: Oct 05, 2025, 11:22 PM