Join Jungwoo Ryoo for an in-depth discussion in this video Visitor example, part of Design Patterns with Python.
- So we'll start with the class that's being visited.…The class is called House…and we'll be defining the class.…One of the main features of the House class is…this method that triggers the visiting operation.…The method is called accept…and we'll be defining…the method here.…In fact, all it does is,…getting this visitor instance…and then invoke this visit method…on this visitor instance.…
So, the visitor instance…is coming in as an argument.…So we'll just type visitor…. and then…visit is the name of the method.…And for the visitor to be able to visit,…it needs a reference to this House class…or the instance of the House class.…That's why we type self here.…So depending on the type of visitors,…we'll be invoking either this method…called work_on_hvac…right here…and this method is only called…when the visitor is hvac_specialist…and then we have another method…called work_on_electricity…and this method is only called by…an electrician visitor.…
So the work_on_hvac method is already defined.…As you can see, all it does is…
- 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.
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?
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.