Browse Java Design Patterns & Enterprise Application Architecture

Functional Strategies with Lambdas

Use lambdas for Java strategies when the behavior is small and the strategy contract is naturally functional.

Modern Java often implements Strategy more cleanly with a functional interface and a lambda than with a pile of small named classes.

1@FunctionalInterface
2public interface RetryPolicy {
3    Duration nextDelay(int attempt);
4}

Then callers can supply strategies inline:

1RetryPolicy exponential = attempt -> Duration.ofMillis(100L << attempt);
2RetryPolicy fixed = attempt -> Duration.ofMillis(250);

When Lambdas Help

Lambdas are a strong fit when:

  • the contract is genuinely single-method
  • the behavior is short
  • naming each strategy class would add more ceremony than clarity

When Named Types Are Better

Prefer concrete classes when:

  • the strategy has internal state or configuration worth naming
  • the algorithm is non-trivial
  • the strategy needs documentation or reuse across the codebase

The right implementation style is the one that makes the behavior easiest to recognize, not the one that uses the most modern syntax.

Revised on Thursday, April 23, 2026