From the course: Python: Design Patterns
Unlock this course with a free trial
Join today to access over 24,600 courses taught by industry experts.
Adapter example - Python Tutorial
From the course: Python: Design Patterns
Adapter 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 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 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, will 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 underscore object to the value of the argument we're receiving called object. Whatever instance of a class we're receiving is going to initialize the…
Contents
-
-
-
-
-
(Locked)
Decorator1m 5s
-
(Locked)
Decorator example4m 43s
-
(Locked)
Solution: Decorator1m 55s
-
Proxy1m 22s
-
(Locked)
Proxy example5m 23s
-
(Locked)
Adapter48s
-
(Locked)
Adapter example6m 16s
-
(Locked)
Composite1m 21s
-
(Locked)
Composite example5m 25s
-
Solution: Composite1m 44s
-
(Locked)
Bridge1m 14s
-
(Locked)
Bridge example5m 31s
-
(Locked)
-
-
-