Observer Pattern

A pattern where subscribers are notified automatically when something changes.

What is Observer Pattern?

The Observer pattern lets objects subscribe to another object and be told when something happens. A YouTube channel notifies all its subscribers when a new video goes up.

public class Channel
{
    public event Action<string>? VideoPublished;
    public void Publish(string title) => VideoPublished?.Invoke(title);
}

channel.VideoPublished += title => Console.WriteLine(quot;New video: {title}");

Level: Freelancer · More OOP terms at this level

Updated