课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Visitor example
- [Instructor] We'll start with defining the class that's being visited. The class is called house. One of the main features of the house class is this method that triggers the visiting operation. The method is called accept, and we'll be defining the method here. It gets this visitor instance and then invokes the visit method on a visitor instance. Type visitor. and visit is the name of the method, self. For the visitor to be able to visit, it needs a reference to an instance of the house class. That's why we type self here. We'll invoke this method called work underscore on hvac only when the visitor is hvac underscore specialist. We have another method called work underscore on underscore electricity, an electrician visitor calls. We already defined the work on hvac method, it displays this message worked on by so-and-so, which will be the name of the object. In this case, the hvac underscore specialist object. Will…
内容
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-