课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Adapter pattern example - Python教程
课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Adapter pattern example
- [Instructor] Let's start by defining the classes whose methods will be used by our Adapter class. We have this class called Korean. It has an attribute called name which is set to Korean, and it has a method that returns a string object that says An-nyeong which means hello in English. We also have the British class that has the same attribute. However, in this case, the method name is different. It is speak_english instead of speak_korean. Let's finish the definition of this class. Here, we'll say self.name which is set to British, and the method will return a string object. Because this is an English speaker, we'll return Hello. Now, let's define the Adapter class that changes the generic method name into individualized method names. Let's start by defining the init method. In the init method, all we're doing is setting the attribute _object to the value of the argument we're receiving called object. Whatever…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。