Join Jungwoo Ryoo for an in-depth discussion in this video Adapter example, part of Python: Design Patterns.
- Let's start by defining these classes…whose methods will be used by our adapter class.…So, we have this class called Korean,…and it has an attribute name,…which is set to Korean,…and it has a method…which simply returns a string object…that says An-meyong.…We also have the British class,…which has the same attribute.…However, in this case, the method name is different.…So, the method name is speak_english,…instead of speak_korean.…
So, let's complete the definition of this class.…So, here we will say…self.name,…which is set to British.…And then, in the method, we'll be simply returning…a string object.…Because this is an English speaker,…we'll be returning "Hello."…Now, let's define the adapter class.…This adapter class changes the generic method name…to individualized method names.…
Let's start by defining the init method.…In the init method all we're doing is…we're setting this attribute_object…to the value of the argument we're receiving,…called object.…So, whatever instance of object we're receiving,…it's going to be initializing _object.…
- Understanding design patterns
- Best design practices: consistency, completeness, and correctness
- Working with creational patterns
- Working with structural patterns
- Working with behavioral patterns
Skill Level Intermediate
Q: In the strategy pattern example, why does the code keep executing the default function rather than the alternate?
A: The programming demonstration skips the step of defining what the strategy pattern should be when an alternate function name is provided
as an argument as shown below.
1. Understanding Design Patterns
2. Creational Patterns
3. Structural Patterns
4. Behavioral Patterns
5. Design Best Practices
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.