Order Status Observers

Hard ⏱ 18 min 32% acceptance ★★★★☆ 4.2
Build a minimal observer pattern: OrderTracker has subscribe(callback) and update(status) — updating stores the status and calls every subscribed callback with it. Write it so callbacks added later miss earlier statuses (no replay). Demonstrate with a list-appending callback.

Examples

Example 1
Input
t = OrderTracker(); log = []; t.subscribe(log.append); t.update('packed'); log
Output
['packed']
Explanation

The callback fired on update.

Constraints

  • Support multiple subscribers.
  • update calls each with the new status.

Topics

OOPobserver pattern

Companies

ZomatoSwiggyDoorDash

Hints

Hint 1

Store callbacks in a list.

Hint 2

Loop and call them inside update.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.