This phase adds side-by-side examples to show how the same pattern can be implemented in three styles:
- Classic OO implementation
- Functional/lambda-first implementation
- Java 21+ friendly implementation (records, sealed interfaces, switch pattern matching, virtual threads)
Package: org.example.modern_java
StrategyVariants.ClassicCalculator: interface-based strategy injection.StrategyVariants.FunctionalCalculator:IntBinaryOperatorstrategy via lambda.StrategyVariants.ModernCalculator: sealed operation hierarchy (Add,Multiply) with pattern matching switch.
ObserverVariants.ClassicSubject: concrete observer interface list.ObserverVariants.FunctionalSubject:Consumer<String>subscribers.ObserverVariants.ModernPublisher:Flow.PublisherviaSubmissionPublisher.
CommandVariants.ClassicInvoker: command objects implementingexecute.CommandVariants.FunctionalInvoker: queuedSupplier<String>commands.CommandVariants.ModernInvoker: sealed command records and switch dispatch.
Implemented in ConcurrencyPatternsPack:
- Producer-Consumer with virtual threads
producerConsumerWithVirtualThreads(int itemCount)usesExecutors.newVirtualThreadPerTaskExecutor().
- Bounded queue/backpressure
BoundedBackpressureQueue<T>wrapsArrayBlockingQueueand provides timedtryPublish.
- Thread confinement / immutable handoff
ThreadConfinedMailbox<T>runs consumption on a dedicated single thread.ImmutableMessagerecord models immutable handoff data.
ModernJavaVariantsTestvalidates all new variants end-to-end.