课程: Node.js: Design Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Chain of responsibility

Chain of responsibility

- [Instructor] Think about ordering a sandwich from your favorite sub shop. The first thing that you might be asked to select is the bread. Then you might have to select the meat. Followed by the cheeses. Followed by the vegetables. And finally to the condiments. You're sandwich gets made on an assembly line. The steps that go into making that sandwich are ordered. And you can claim the sandwich at any point in the process. If you only want meats and cheeses, then the sandwich doesn't need to complete the rest of the steps on line. You can just take it and eat it. This analogy is similar to the Chain of Responsibility design pattern. This pattern allows us to chain together objects to handle a request. A request is sent to an object to handle it and then that handler could process the request and return a result, or it could pass the request on to the next handler. Which could return a result or pass the request…

内容