paper

Deprecating the Observer Pattern

  • Authors:

📜 Abstract

Programming interactive systems by means of the observer pattern is hard and error-prone yet is still the implementation standard in many production environments. We present an approach to gradually deprecate observers in favor of reactive programming abstractions. Several library layers help programmers to smoothly migrate existing code from callbacks to a more declarative programming model. Our central high-level API layer embeds an extensible higher-order data-flow DSL into our host language. This embedding is enabled by a continuation passing style transformation.

✨ Summary

Summary

The paper argues that conventional observer-based event handling creates excessive coupling and boilerplate, promotes shared mutable state, complicates resource management, weakens separation of concerns, and can produce inconsistent intermediate states, or glitches. It uses mouse-drag handling as a representative example of the difficulty of expressing stateful event sequences with independently installed callbacks.

The proposed solution is Scala.React, a layered reactive-programming framework that provides a gradual migration path from observers to more declarative abstractions. The layers include:

  • First-class event streams, represented by Events[A], with uniform operations such as observation, merging, mapping, filtering, and collection.
  • Reactors, which allow programmers to express event-driven state machines directly using operations such as next, delay, and looping constructs, thereby reducing inversion of control.
  • Signals, which represent time-varying values and automatically track dependencies in expressions such as Signal { a() + b() }.
  • Data-flow reactives, which combine event processing, state transitions, and signal updates through operations including emit, switchTo, next, and delay.
  • A generalized reactive hierarchy, intended to support additional abstractions such as futures, incrementally changing documents, lists, and paths.

The implementation uses discrete propagation cycles. Reactives are synchronized before observers execute, and a push-driven scheduler maintains a topological ordering of dependencies to prevent glitches. Dynamic dependencies are handled by detecting level mismatches and rescheduling pure reactive computations. Side effects are restricted because signal expressions may be reevaluated; reactors remain the intended mechanism for externally visible effects. The data-flow language is implemented using delimited continuations and a selective continuation-passing-style transformation, including special handling for loops and exceptions on the JVM.

The paper’s principal contribution is architectural: it shows how functional reactive programming, imperative state-machine code, object-oriented interfaces, and low-level observers can coexist in a single statically typed framework. The result is not a claim that observers disappear entirely, but a structured path for replacing ad hoc callbacks with composable, encapsulated, and consistency-preserving reactive abstractions.

Documented influence

The paper directly influenced subsequent Scala reactive libraries. The Scala.Rx project explicitly states that its push-based functional-reactive implementation is based on ideas from this work, particularly its reactive variables and dependency-graph propagation model. (github.com) Later Scala reactive systems and documentation, including REScala-related material, continue to list the Scala.React work among the relevant foundations for object-oriented and functional reactive programming. (rescala-lang.com) Subsequent research has also cited Scala.React as an academic reactive-language system when discussing models that combine reactive and imperative computation, including the Actor-Reactor Model. (drops.dagstuhl.de)

The paper also had concrete practitioner influence: Scala.Rx documentation and other Scala ecosystem discussions identify it as a design source, while independent projects have used the paper as the starting point for implementations in other languages, including an experimental reactive-programming library in C. (github.com) The available evidence supports influence on research prototypes and Scala libraries; it does not establish widespread direct adoption of Scala.React itself in mainstream industry frameworks.