From the course: JavaScript: Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Chain of responsibility

Chain of responsibility - JavaScript Tutorial

From the course: JavaScript: Patterns

Start my 1-month free trial

Chain of responsibility

- [Instructor] The Chain of Responsibility is a pattern to help solve common practical issues of having a request from a client and needing this request to pass through multiple functions or logic to get the result. This is where chain of responsibility comes into play. So let's illustrate this with an example. When you hit the Buy button, this particular request goes through a series of functions to finalize the order, and they can quickly grow in complexity. So we hit the Buy button, then the application needs to check if you're logged in, then needs to check if it has your address. If not, add an address. Then it needs to calculate the taxes, shipping, process payment, and finally process the order, and display success message. Needles to say, this simple action of clicking by has several functions related to it, and if we are to build this application with a modular approach and pure functions, we're talking close to a…

Contents