Skip to main content


StructuralGang Of FourDecouplingAbout 3 min


Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level
interface that makes the subsystem easier to use.


Real-world example

How does a goldmine work? "Well, the miners go down there and dig gold!" you say. That is what you
believe because you are using a simple interface that goldmine provides on the outside, internally
it has to do a lot of stuff to make it happen. This simple interface to the complex subsystem is a

In plain words

Facade pattern provides a simplified interface to a complex subsystem.

Wikipedia says

A facade is an object that provides a simplified interface to a larger body of code, such as a
class library.

Programmatic Example

Let's take our goldmine example from above. Here we have the dwarven mine worker hierarchy. First
there's a base class DwarvenMineWorker:

public abstract class DwarvenMineWorker {

    public void goToSleep() {"{} goes to sleep.", name());

    public void wakeUp() {"{} wakes up.", name());

    public void goHome() {"{} goes home.", name());

    public void goToMine() {"{} goes to the mine.", name());

    private void action(Action action) {
        switch (action) {
            case GO_TO_SLEEP -> goToSleep();
            case WAKE_UP -> wakeUp();
            case GO_HOME -> goHome();
            case GO_TO_MINE -> goToMine();
            case WORK -> work();
            default ->"Undefined action");

    public void action(Action... actions) {;

    public abstract void work();

    public abstract String name();

    enum Action {

Then we have the concrete dwarf classes DwarvenTunnelDigger, DwarvenGoldDigger and

public class DwarvenTunnelDigger extends DwarvenMineWorker {

  public void work() {"{} creates another promising tunnel.", name());

  public String name() {
    return "Dwarven tunnel digger";

public class DwarvenGoldDigger extends DwarvenMineWorker {

  public void work() {"{} digs for gold.", name());

  public String name() {
    return "Dwarf gold digger";

public class DwarvenCartOperator extends DwarvenMineWorker {

  public void work() {"{} moves gold chunks out of the mine.", name());

  public String name() {
    return "Dwarf cart operator";

To operate all these goldmine workers we have the DwarvenGoldmineFacade:

public class DwarvenGoldmineFacade {

  private final List<DwarvenMineWorker> workers;

  public DwarvenGoldmineFacade() {
      workers = List.of(
            new DwarvenGoldDigger(),
            new DwarvenCartOperator(),
            new DwarvenTunnelDigger());

  public void startNewDay() {
    makeActions(workers, DwarvenMineWorker.Action.WAKE_UP, DwarvenMineWorker.Action.GO_TO_MINE);

  public void digOutGold() {
    makeActions(workers, DwarvenMineWorker.Action.WORK);

  public void endDay() {
    makeActions(workers, DwarvenMineWorker.Action.GO_HOME, DwarvenMineWorker.Action.GO_TO_SLEEP);

  private static void makeActions(Collection<DwarvenMineWorker> workers,
      DwarvenMineWorker.Action... actions) {
    workers.forEach(worker -> worker.action(actions));

Now let's use the facade:

var facade = new DwarvenGoldmineFacade();

Program output:

// Dwarf gold digger wakes up.
// Dwarf gold digger goes to the mine.
// Dwarf cart operator wakes up.
// Dwarf cart operator goes to the mine.
// Dwarven tunnel digger wakes up.
// Dwarven tunnel digger goes to the mine.
// Dwarf gold digger digs for gold.
// Dwarf cart operator moves gold chunks out of the mine.
// Dwarven tunnel digger creates another promising tunnel.
// Dwarf gold digger goes home.
// Dwarf gold digger goes to sleep.
// Dwarf cart operator goes home.
// Dwarf cart operator goes to sleep.
// Dwarven tunnel digger goes home.
// Dwarven tunnel digger goes to sleep.

Class diagram

alt text
Facade pattern class diagram


Use the Facade pattern when

  • You want to provide a simple interface to a complex subsystem. Subsystems often get more complex
    as they evolve. Most patterns, when applied, result in more and smaller classes. This makes the
    subsystem more reusable and easier to customize, but it also becomes harder to use for clients that
    don't need to customize it. A facade can provide a simple default view of the subsystem that is good
    enough for most clients. Only clients needing more customization will need to look beyond the
  • There are many dependencies between clients and the implementation classes of an abstraction.
    Introduce a facade to decouple the subsystem from clients and other subsystems, thereby promoting
    subsystem independence and portability.
  • You want to layer your subsystems. Use a facade to define an entry point to each subsystem level.
    If subsystems are dependent, then you can simplify the dependencies between them by making them
    communicate with each other solely through their facades.


*DigitalOceanopen in new window