课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Observer example
- [Instructor] We start with the subject class that represents what is being observed. The subject class keeps this list called _observers where references to all the observers are being kept. Note that this is a one to many relationship. There'll be only one subject to be monitored by multiple observers. Next is defining the attach method. This method accepts an observer as an argument. With this observer object, we'll first check if the observer is not already on the observer list. Type if observer not in self._observers: We'll try to append the observer to the list only when it's not already on the list. And that's our next statement: type self._observers append(observer). The next method is the detach method that removes an observer from the observer list. The last method is our notify method. This is the most important method in the subject class because it notifies all the observers when there is a change in the…
内容
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-