From the course: Python: Design Patterns (2021)
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Adapter example - Python Tutorial
From the course: Python: Design Patterns (2021)
Adapter example
- [Instructor] Let's start by defining the classes who's methods will be used by our adapter class. We have this class called Korean. It has the attribute name, which is set to Korean, and it has a method that returns a string object that says, An-neyong which means hello in English. We also have the previous class that has the same attribute. However, in this case, the method name is different. It is speak underscore English instead of speak underscore Korean. Let's finish the definition of this class. Here, we'll say self dot name, which is set to British and the method will return a string object because this is an English speaker will return hello, return hello. Now let's define the adaptive 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 underscore object to the value of the argument…