270 | Chapter 7: Command Pattern
The example application will look like Figure 7-4 with an additional “Undo” button.
Command “redo” functionality including logging features can be implemented in
similar ways. Logging features are useful when the commands executed need to be
saved on disk. For example, saving the installation command objects on disk when a
new application is installed will facilitate an uninstall by loading the logged com-
mands and undoing them in reverse order.
Example: Podcast Radio
This example implements a classic car radio with a twist. Instead of programming
the push buttons to tune to a radio station, they will be attached to command objects
that will download and play the latest episode from a podcast. Think of this as a
futuristic car radio when long-range Wi-Fi becomes a reality. You can listen to the
NPR hourly news summary on demand without waiting for the top of the hour.
Figure 7-5 shows the screen layout of the application. It consists of labeled buttons
that indicate the genre of the podcast assigned to each button, and a text field that
displays the title of the podcast item that is currently playing.
What Is a Podcast?
A podcast is a media file that is distributed over the Internet. Podcasts are distrib-
uted using a syndication feed, which is a standard way of distributing content that is
regularly updated. The feed is an XML file just like a syndicated news feed that lists
news stories with the most recent one first. The difference between news feeds and
26 panel.setCommand(1, decCommand);
27 panel.setCommand(2, undo);
Figure 7-5. Screenshot of podcast radio
Example 7-24. Client code for undoable number manipulator