Join Jungwoo Ryoo for an in-depth discussion in this video Factory example, part of Design Patterns with Python.
- View Offline
- Exercise Files
- We just defined this Dog class.…The Dog class, whenever it is created,…calling this init method which is a setting,…the name of the dog,…and then it has a method called speak…and it simply returns a string, "Woof!"…Now, let's create a new function called get_pet.…So type def get_pet.…Now, we've passing this key value combination…because whatever argument we're passing will be stored…in a dictionary object.…
We've passing this argument which is going to be used…as a key in the dictionary object.…The name of the variable is pet,…we'll initialize that variable with dog,…just a string, initial string.…So the default value of pet is dog.…Then we'll define this function…by adding some internal documentation first.…Since this is the factory method…we'll be using to create our object,…we'll simply say it,…***The factory method***.…
In the factory function,…the mission is really to create these objects…and to return these objects to the user of the function.…We'll be storing those objects being created…into a variable called pets.…
- 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
Foundations of Programming: Design Patternswith Elisabeth Robson2h 19m Intermediate
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?
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.