Skip to content
GDP for Noobs
☰ All patterns
StructuralBeginner

Facade

One simple front door to a complicated system.

01

Explain it like I'm new

Real-life analogy

A hotel concierge

You tell the concierge 'I want dinner and a taxi at 8'. Behind the scenes they call the restaurant, the taxi firm and the front desk. You only talk to one person.

😩 The problem

Placing an order touches inventory, payments, shipping and email. Every caller has to know the right order of calls and handle each failure.

💡 The pattern

Create a type with one high-level method (PlaceOrder) that orchestrates the subsystems. Callers use the simple method; experts can still use the subsystems directly.

02

Walk through the code

Click a step to highlight its lines. This is a complete program you can copy and run.

main.go
1package main
2
3import "fmt"
4
5// --- A bunch of subsystems, each with its own API ---
6
7type Inventory struct{}
8
9func (Inventory) Reserve(item string) error {
10 fmt.Println(" inventory: reserved", item)
11 return nil
12}
13
14type Payments struct{}
15
16func (Payments) Charge(user string, amount float64) error {
17 fmt.Printf(" payments: charged %s $%.2f\n", user, amount)
18 return nil
19}
20
21type Shipping struct{}
22
23func (Shipping) Schedule(user, item string) string {
24 fmt.Println(" shipping: scheduled delivery for", user)
25 return "TRK-1001"
26}
27
28type Mailer struct{}
29
30func (Mailer) Send(user, msg string) { fmt.Printf(" mailer: to %s: %q\n", user, msg) }
31
32// OrderFacade hides all four subsystems behind ONE simple method.
33type OrderFacade struct {
34 inventory Inventory
35 payments Payments
36 shipping Shipping
37 mailer Mailer
38}
39
40func (f *OrderFacade) PlaceOrder(user, item string, price float64) error {
41 if err := f.inventory.Reserve(item); err != nil {
42 return err
43 }
44 if err := f.payments.Charge(user, price); err != nil {
45 return err
46 }
47 tracking := f.shipping.Schedule(user, item)
48 f.mailer.Send(user, "Your order ships! Tracking: "+tracking)
49 return nil
50}
51
52func main() {
53 shop := &OrderFacade{}
54 fmt.Println("Placing order...")
55 // The caller writes ONE line instead of orchestrating four systems.
56 if err := shop.PlaceOrder("gopher", "Go T-shirt", 19.99); err != nil {
57 fmt.Println("order failed:", err)
58 }
59 fmt.Println("Done!")
60}
terminal
Press ▶ Run to execute this program.

This output was captured by running the program with Go 1.24. Copy it into your editor or the Go Playground and try changing things.

03

When should I use it?

✅ Reach for it when…

  • •Complex subsystems most callers only use in one or two common ways.
  • •Defining a clean service layer.

🚫 Skip it when…

  • •The facade grows into a 'god object' that does everything. Split it up.

🐹 Go tip

Many Go 'service' structs are facades: they hold repositories and clients and expose business-level methods.

🌍 You've already seen it in

http.Get(url) hides Client, Transport, connection pooling and TLS behind one call.

04

Quick check

One question. No pressure.

http.Get(url) hides the Client, Transport and connection pool. That makes it a...

Related: Adapter, Proxy