We use 1-recursion to abstract the handler class:

  • Every handler can have 1 follower.
  • Handlers attempt to handle request one at a time.
  • Once handled, we can decide to hand to next handler or stop.
  • Can adjust chain dynamically.

Benefits:

  • Each case nicely encapsulated
    • Can be treated in isolation
    • More compact view of all cases possible
  • Possibility to dynamically adjust request handling as needed
  • Can be declaratively configured
    • This is what many modern web frameworks do for route management

Disadvantages:

  • Object structure must be set up explicitly with objects constructed at run time
  • Object proliferation