g ∘ f patterns
summary
Argues that many GoF behavioral patterns are workarounds for missing higher‑order functions and shows live Java code that replaces them with lambdas, streams and function types: rewrites Command as Java 8 lambdas over Runnable, Strategy as a Predicate + Function, Template as a resource- lending method using Consumer that always disposes, Decorator as function composition with DoubleUnaryOperator, Chain of Responsibility as a Stream of functions returning Optional (and uses Optional.stream in Java 9), Interpreter via a Map of BinaryOperator and stack, and a pattern‑matching DSL (Vavr-style); examples compile and produce the same results while removing boilerplate.
AI-written summary · about
chapters (12)
- 0:00Introduction to talk
- 1:51Behavioral patterns in GoF
- 3:16Command pattern in Java
- 8:15Strategy pattern in Java
- 11:52Template method pattern
- 16:12Observer pattern skipped
- 16:34Tax calculation with decorators
- 23:49Function composition for taxes
- 24:09Chain of responsibility
- 35:48Interpreter pattern in RPN
- 41:10Visitor pattern for geometry
- 49:23Summary and conclusions
