Join Jungwoo Ryoo for an in-depth discussion in this video Chain of responsibility example, part of Python: Design Patterns.
- Let's start by first defining…our handler class,…which is an abstract handler.…Since the point of a handler…is to find the successor,…if the current handler is not able to handle the request…we need an attribute to store…a successor handler.…So, type…self._…successor =,…and the successor handler is…coming in as an argument in the…init method, as you can see here.…
So, the name of it is successor,…s-u-c-c-e-s-s-o-r.…So the next method is…this handle method,…and in the handle method…we'll first try to handle the request…and see what happens.…To handle the request, we simply cull,…_handle method.…So, just type…self._handle,…and then the request.…
So, when we invoke this _handle method…it will try to handle the request.…If it is able to handle the request…it will return this True value.…So, this variable handled…will be initialized to have a True value…if the handling was successful.…So the next part of our code is…checking this valued in the handled variable,…as you can see here.…So, if the _handle request method…couldn't handle the request,…
- 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.
Programming Foundations: 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.