jeudi 8 septembre 2022

What is the name of this decorator/handler chain implemented using iteration?

I have a design pattern which has commonalities and differences with the following:

  • The decorator pattern is built on composition, where each decorator has a reference to the next decorator in the chain.
  • The middleware pattern moves knowledge of the next handler outside of the handlers themselves, providing a next method.
  • Chain of Responsibility is more like the middleware pattern, except only one handler chooses to take an action and the chain is terminated.

In contrast with the above, my design pattern does not rely on recursion or nested composition, and does not have a next method.

  • A list of handlers are called in order by a "Sequence Controller"
  • Each handler takes X as an argument, then provides a new value for X.
  • Any number of handlers might perform an action

So there's a controller that handles the sequencing - you could stop or pause the sequence from somewhere outside while it's running (including one of the handlers, if it is a handler that happens to be aware of the sequence controller), unlike with the decorator or middleware patterns.

This pattern seems very useful because it keeps handlers generic (Sequence Controller is one of many possible strategies for executing the handlers), and does not increase the size of the call stack.

I would like to know is if this design pattern has been described before and already has a name and terminology to go with it. (for example I call these handlers but maybe they're called "Invokable" or "Step")

Aucun commentaire:

Enregistrer un commentaire