Polski

Order observer

An order notifies subscribers when its status changes; subscriptions can be cancelled and an audit log records transitions.

medium · csharp · typescript · 20 XP

When an order changes status, several parts of the system must react (customer e-mail, warehouse, audit). The order should not know them – it just notifies observers.

Task

  1. Subscribe / subscribe adds an observer and returns a cancellation handle (IDisposable in C#, a function in TypeScript).
  2. ChangeStatus / changeStatus:

    • the same status → nothing happens (no notifications),
    • after Delivered or Cancelled a change is not allowed (InvalidOperationException / Error),
    • otherwise it changes the status and notifies all observers in subscription order, passing the previous status.
  3. AuditLog stores entries like #7: New -> Paid (TypeScript: #7: new -> paid).

Topics: Observer