Chapter 17. The Command Pattern
The Chain of Responsibility pattern forwards requests along a chain of classes, but the Command pattern forwards a request only to a specific object. It encloses the request for a specific action inside an object and gives it a known public interface. It lets you give the client the ability to make requests without knowing anything about the actual action that will be performed and allows you to change that action without affecting the client program in any way.
When you build a Java user interface, you provide controls—menu items, buttons, check boxes, and so on—to allow the user to tell the program what to do. When a user selects one of these controls, the program receives an ActionEvent, which it must ...