Join Jungwoo Ryoo for an in-depth discussion in this video Memento example, part of Python: Advanced Design Patterns.
- [Instructor] In this memento example,…we import the pickle module.…The pickle module allows us to serialize…and de-serialize Python objects.…In other words, it can transform an object…into a tech stream before saving it into a file.…The reverse is also possible and referred to as…de-serializing.…We'll use this useful feature, provided…by the pickle module in our example…to demonstrate how we can save the state…of an object at a certain time…and restore its previous state.…
Let's first define our originator class.…Here we can create a constructor…that sets the initial state of an originator object…to none by typing self._state = None.…We then define our method to create a memento object,…the name of the method is create_memento.…
Type "return pickle.dumps(vars(self))".…All this does is using the pickle module method…called dumps and turns an originator object…into a character stream.…By the way, the VARS method is a built in…Python function that returns a dictionary…containing all the attribute value pairs…of an object.…
- Architectural vs. design patterns
- Why use design patterns?
- Design best practices
- Domain-specific patterns and security patterns
- Gang of Four design patterns
- Command, Mediator, and State
- Template method
Skill Level Advanced
Learning Python and Django (2015)with Caleb Smith1h 11m Intermediate
Programming Foundations: Design Patternswith Elisabeth Robson2h 19m Intermediate
1. Understanding Design Patterns: Review
2. Design Best Practices
3. Gang of Four (GoF) Patterns, Part 1
4. Gang of Four (GoF) Patterns, Part 2
Next steps1m 26s
- 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.