DevPrep

All topics › Software architecture

Delegate or notification — when to choose which?

Middle PRO

The point

These are three different ways to say "something happened", and the choice depends on the number of receivers and the strength of coupling:

On "synchronicity": a delegate and a closure are called directly, and notifications sent with post are also delivered synchronously on the sender's thread — this is not a selection criterion. The criterion is coupling and the number of subscribers.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store