Search⌘ K
AI Features

Consequences and Comparison

Understand the Reactor pattern by exploring how it improves event-driven applications in C. Learn about its single-responsibility principle benefits, open-closed principle adherence, and comparison with the Observer pattern, focusing on notification mechanisms, cohesion, and modular event handling.

Comparison of Reactor and Observer

Although the mechanisms used to implement them are related, there are differences between these two patterns. The main difference is in the notification mechanism. As a Subject changes its state in an Observer implementation, all its dependents (observers) are notified. In a Reactor implementation, this relationship is one to one – a detected event leads the Reactor to notify exactly one dependent (EventHandler).

One typical liability of the Observer pattern is that the cohesion of the subject is lowered; besides serving its central purpose, a subject also takes on the responsibility of managing and notifying observers. With this respect, a Reactor differs significantly as its whole raison d’être is to dispatch events to its registered handlers.

Consequences

The main consequences of applying the Reactor ...