课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Chain of responsibility example
- [Instructor] Let's start, by first defining our handler class, which is an abstract handler. Since the point of a handler is to find its successor. If the current handler cannot handle a request, we need an attribute to store a successor handler. Type self._successor. The successor handler is coming in as an argument, in the in it method, the next method is the handle method in which will first try to handle the request. To handle the request we call _handle method. If this method is able to handle the request, it will return the true value. The next part of our code is checking the value, in the handled variable as you can see here. If the _handle request method, couldn't handle the request, then we have to do something else, which is using a successor. That's why we type self._successor.handle request, this _handle method provides an interface, to be implemented by the following concrete handler classes. Let's go…
内容
-
-
-
-
-
-
(已锁定)
Observer1 分钟 5 秒
-
(已锁定)
Observer example6 分钟 22 秒
-
(已锁定)
Visitor56 秒
-
(已锁定)
Visitor example6 分钟 42 秒
-
(已锁定)
Iterator1 分钟 15 秒
-
(已锁定)
Iterator example4 分钟 32 秒
-
(已锁定)
Strategy40 秒
-
(已锁定)
Strategy example5 分钟 44 秒
-
(已锁定)
Chain of responsibility1 分钟 4 秒
-
(已锁定)
Chain of responsibility example5 分钟 57 秒
-
(已锁定)
-
-