Structural

Facade

Provides a simplified interface to a complex subsystem.

Library APIsService layersComplex operations

Understanding Facade

The Facade pattern provides a simplified, unified interface to a complex subsystem of classes, libraries, or frameworks. Rather than exposing the subsystem's intricate API to client code, the facade wraps the complexity behind a single, easy-to-use method. In Go, facades are typically structs that aggregate multiple subsystem components and provide high-level methods that orchestrate their interactions — like an order processing facade that coordinates inventory, payment, and shipping behind a single PlaceOrder() call.

Key Concepts

  • Simplified interface — provides a few high-level methods instead of exposing dozens of subsystem APIs
  • Subsystem orchestration — the facade coordinates multiple subsystem components to fulfill complex operations
  • Not a restriction — clients can still access subsystem components directly for advanced use cases
  • Dependency reduction — client code depends only on the facade, not on the subsystem classes

When to Use

✅ Use when
  • • A subsystem has grown complex with many interacting components
  • • You want to layer your system with a clean entry point for each layer
  • • Client code needs to perform multi-step operations across multiple services
  • • You want to reduce coupling to third-party library internals
⚠️ Avoid when
  • • The facade becomes a "god object" that does too much
  • • The subsystem is simple enough that direct usage is clearer
  • • You need fine-grained control that the facade hides

Structure

Client
↓ simple call
Facade (PlaceOrder, Start, etc.)
↓ orchestrates
SubsystemA
SubsystemB
SubsystemC

How It Works

Client
Facade
PlaceOrder()
Subsystem
Inventory
Payment
Shipping
1

Complex Subsystem

Multiple interconnected components with complex interfaces.

1 / 4

Basic Implementation

Computer startup facade hiding complex boot sequence:

main.go
Loading editor...

Real-World Example: E-commerce Order

Order processing facade coordinating inventory, payment, and shipping:

main.go
Loading editor...