Repaso
Español
Design & PracticesIntermediateDP-11

Which pattern fits 'notify email, analytics and inventory services whenever an order is placed'?

Options

  1. Observer: subscribers are notified of each new order (Correct option)
  2. Singleton: one shared service handles every order
  3. Builder: each order is assembled step by step
  4. Prototype: each order is cloned from a template

Answer

Observer (publish/subscribe)

Why

Observer: an object (the subject) keeps a list of subscribers and notifies all of them when something happens.

The order code just announces 'order placed'; it does not know who listens. You can add a new listener (e.g. loyalty points) without touching the order code.

In bigger systems the same idea becomes an event bus or message queue.

Remember

Observer = 'tell everyone who subscribed'.

Key terms

Practice this question in Repaso