Chain of responsibility

Intent

  • Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
  • Launch-and-leave requests with a single processing pipeline that contains many possible handlers.
  • An object-oriented linked list with recursive traversal.

Structure

COR vs Decorator

  • The fact that you can break the chain at any point differentiates the Chain of Responsibility pattern from the Decorator pattern.
  • Its around the order in which things will happen. If you chain them, then things will be called along the chain. With a decorator you're not guaranteed this order, only that additional responsibilities can be attached.

Hands on ...

Null object

(anti-)pattern?

Intent

  • Is to encapsulate the absence of an object by providing a substitutable alternative that offers suitable default do nothing behaviour.
  • In short, a design where "nothing will come of nothing"

Null Object

  • The Null Object class is often implemented as a Singleton. Since a null object usually does not have any state, its state can't change, so multiple instances are identical. Rather than use multiple identical instances, the system can just use a single instance repeatedly.
Made with Slides.com