Chain of Responsibility

There was 100 years ago, Ford Motor Company made the T-Model.
The revolution was to use an assembly line production.
This kind of production is always used nowadays.
The car is put on a conveyor belt.
The car has to cross some steps before to be considered like finished.
If there is a problem at only one step, the car won't go to the next steps.

These main steps are:
  1. Remove the doors
  2. Install the dashboard
  3. Install the seats and windows
  4. Install bumpers
  5. Install the engine
  6. Install brakes and suspensions
  7. Put the doors back
  8. Install the wheels
  9. Adjustment
  10. Check
THIS IS THE CHAIN-OF-RESPONSIBILITY DESIGN PATTERN !!!

When you will be in the same situation =
An object has to be subject to a series of processes, checks, treatments, ...

Don't code these treatments in the same place, just make a chain of responsibility.

All the treatments will implement the same interface.
So it will be easy to create a new treatment.
Each treatment will know the next treatment and call it if all is ok.
The object just will cross all the treatments without know them.
You can have a central object containing the chain.
This object will be able to add a treatment at the end of the chain.



Links with other design patterns:

We can change one ore several steps of the chain by a composite easily.