THN Interview Prep

Facade (Structural)

Intent / problem it solves

Provide a unified higher-level interface to a set of interfaces in a subsystem, simplifying common workflows and reducing coupling for most clients.

When to use / when NOT

Use when a module exposes many small services; wrap frequent sequences (checkout, deploy, onboarding).

Avoid when it becomes a god object; keep facades thin and push logic down.

Structure

Facade coordinates subsystem classes; clients depend only on the facade for common paths.

Loading diagram…

Go example

package main

import "fmt"

type Inventory struct{}

func (Inventory) Reserve(sku string) bool { return sku != "" }

type Payment struct{}

func (Payment) Charge(amount int) bool { return amount > 0 }

type Shipping struct{}

func (Shipping) Schedule(address string) string { return "tracking-" + address }

type Storefront struct{}

func (Storefront) Buy(sku string, amount int, address string) (string, bool) {
	if !Inventory{}.Reserve(sku) || !Payment{}.Charge(amount) {
		return "", false
	}
	return Shipping{}.Schedule(address), true
}

func main() {
	tracking, ok := Storefront{}.Buy("book", 20, "Main St")
	fmt.Println(tracking, ok)
}

JavaScript example

class AuthService {
  signIn(credentials) {
    return { token: `tok-${credentials.user}` };
  }
}

class ProfileService {
  loadProfile(token) {
    return { token, name: 'Ada' };
  }
}

class SessionFacade {
  constructor(auth, profiles) {
    this.auth = auth;
    this.profiles = profiles;
  }

  openSession(credentials) {
    const session = this.auth.signIn(credentials);
    const profile = this.profiles.loadProfile(session.token);
    return { session, profile };
  }
}

const facade = new SessionFacade(new AuthService(), new ProfileService());
console.log(facade.openSession({ user: 'ada' }));

Interview phrase

“Facade is my narrow entry point: it sequences inventory, payment, and shipping so the mobile app calls one method instead of three services.”

Reference in LLD when a use case orchestrates multiple subsystems in LLD case studies.

Mark this page when you finish learning it.

Last updated on

Spotted something unclear or wrong on this page?

On this page