Designing functional and fluent API: example of the Visitor Pattern
summary
Live coding shows an implementation of the Visitor pattern in Java that avoids mutating state or changing the object model by using lambdas, a Map<Class,Function> registry, and type-safe generics with a few explicit casts. It builds a fluent API (builder/initializer, chained for(type).execute(fn) calls) and a visitable factory that maps functions over an object graph, then reduces results with Collector + Stream reduction to produce joined strings or lists. The example compiles and runs, producing expected concatenated strings and lists.
AI-written summary · about
chapters (8)
- 0:00Start
- 1:29Why the Visitor Pattern
- 17:17Composition over Inheritance
- 21:58Visitor Builder
- 22:57Create a Default Method on the Visitor Builder
- 26:00Create an Init Method
- 47:52Make Visible Default Method
- 49:46Accept Method
related talks
51mFunctional Programming with Java
55mRevisiting Design Patterns After 20
49mJava Functional Programming Idioms
45mRevisiting Design Patterns after 20
55mFunctional Programming Patterns with Java8
44mDesign Patterns in the Light of Lambda Expressions
48mEmbrace the Func - How Far has Functional Programming Come in Java?
01h 01mTransforming Data using the Functional API
