← Back to scenarios
ScenarioCatalog DB

Device setup

Run device pairing, configuration, and health checks through one setup operation.

Problem

A client must prepare a device for use without knowing the sequence or APIs for pairing, configuration, and health-check subsystems.

Related patterns

Implementations

Facade

TypeScriptApplication

Facade in TypeScript

Provides one checkout operation that coordinates inventory, payment, and shipment subsystems without exposing their individual workflows to callers.

TypeScript
type OrderRequest = {
  orderId: string;
  sku: string;
  quantity: number;
  paymentToken: string;
};

class InventoryService {
  reserve(sku: string, quantity: number) {
    console.log(`Reserved ${quantity} of ${sku}`);
  }
}

class PaymentService {
  charge(paymentToken: string) {
    console.log(`Charged payment token ${paymentToken}`);
  }
}

class ShipmentService {
  createShipment(orderId: string) {
    console.log(`Created shipment for ${orderId}`);
  }
}

class CheckoutFacade {
  constructor(
    private readonly inventory: InventoryService,
    private readonly payments: PaymentService,
    private readonly shipments: ShipmentService,
  ) {}

  placeOrder(request: OrderRequest) {
    this.inventory.reserve(request.sku, request.quantity);
    this.payments.charge(request.paymentToken);
    this.shipments.createShipment(request.orderId);
  }
}

const checkout = new CheckoutFacade(
  new InventoryService(),
  new PaymentService(),
  new ShipmentService(),
);

checkout.placeOrder({
  orderId: "order-123",
  sku: "keyboard",
  quantity: 1,
  paymentToken: "token_abc",
});

Associated technologies