O'Reilly logo

Learning Python Design Patterns by Gennadiy Zlobin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Encapsulating Calls with the Command Pattern

In this chapter you will learn about the Command design pattern, how to implement undo and macro operations, and write very simple Unix command variations, which can be cancelled after execution.

Imagine that you are writing the printer program and want to implement the printer spooler. What is the the easiest way to do it? Create a Spooler class with methods to add and remove printer jobs. The easiest way to execute printer jobs is to create an object, which contains all necessary information: text to print, number of copies, color, quality, and so on. The spooler will need to call the execute method of the print job, and the print job will take care of everything by itself.

That's how the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required