Search code examples
javadesign-patternsapache-flink

Flink Context vs TriggerContext


Background

To maintain a state, Trigger uses TriggerContext while the window functions uses Context. Although logically similar, TriggerContext and Context do not seem to share the same code (neither through inheritance nor usage).

Question

Why do TriggerContext and Context don't share the same code and have a different usage pattern?


Solution

  • These two classes are the just the tip of the iceberg; Flink's APIs make frequent use of this Context object pattern. The objective here is to provide user-defined functions with just the information they need, while avoiding any unnecessary coupling between components.