← Back to scenarios
ScenarioCatalog DB

Order status notifications

Broadcast order-status changes so email, warehouse, and analytics consumers react independently.

Problem

An order system must notify multiple downstream concerns when order status changes without embedding email, warehouse, and analytics behavior in the order domain component.

Related patterns

Implementations

Observer

TypeScriptApplication

Observer in TypeScript

Publishes deployment-status changes to independently subscribed notification channels.

TypeScript
interface DeploymentObserver {
  update(status: string): void;
}

class Deployment {
  private readonly observers = new Set<DeploymentObserver>();
  private status = "pending";

  subscribe(observer: DeploymentObserver) {
    this.observers.add(observer);
  }

  unsubscribe(observer: DeploymentObserver) {
    this.observers.delete(observer);
  }

  setStatus(status: string) {
    this.status = status;
    this.notify();
  }

  private notify() {
    for (const observer of this.observers) {
      observer.update(this.status);
    }
  }
}

class SlackNotifier implements DeploymentObserver {
  update(status: string) {
    console.log(`Slack: deployment is ${status}`);
  }
}

class DashboardNotifier implements DeploymentObserver {
  update(status: string) {
    console.log(`Dashboard updated: ${status}`);
  }
}

const deployment = new Deployment();

deployment.subscribe(new SlackNotifier());
deployment.subscribe(new DashboardNotifier());

deployment.setStatus("running");
deployment.setStatus("completed");

Associated technologies