Interpreter Pattern In Light of Java 21
summary
Classic Interpreter bakes evaluation into mutable domain objects so changing interpretation forces edits and mixing of concerns; modern Java 21 split solves that by modeling expressions as a sealed hierarchy of records (Constant, Sum, Subtract, Multiply) and writing external interpreters implemented with sealed classes, pattern matching and switch expressions to produce evaluators that return values, pretty-printed strings, or asynchronous results via CompletableFuture. Examples show a runner evaluating RPN-style expressions, an async evaluator, and notes on bringing in monadic types like Either/Option and type-class-style flatMap to move map/flatMap outside the model.
AI-written summary · about
chapters (9)
- 0:00Introduction to patterns
- 2:39The classic interpreter
- 12:17Modernizing the approach
- 19:25Sealed classes and pattern matching
- 25:40Advanced pattern matching
- 31:00Externalizing interpretations
- 37:11Functional concepts
- 43:00Scala and monadic patterns
- 53:58Future perspectives
related talks
50mModern Java Puzzlers
25mBrewing Patterns in Java - An Informal Primer
56mThe Art of Java Language Pattern Matching
55mRevisiting Design Patterns After 20
55mThe Art of Java Language Pattern Matching
29mThe Art of Java Language Pattern Matching
46mThe Art of Java Type Patterns
43mEnums on steroids - let's look at sealed classes!
