Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 7. Command Pattern > Example: Number Manipulator

7.5. Example: Number Manipulator

The invoker in the previous examples can hold only one command object. However, in real applications, invokers need to hold multiple commands. For example, take the File menu of any application. It is a good example of an invoker. The File menu has Open, Save and Save As menu items. Each of these menu items can be a command container that calls the execute() method of the embedded command object when triggered by the user. Toolbars in applications are also invokers. They generally consist of button icons that execute particular commands to manipulate elements in an application or document.

In the Number Manipulator application (Figure 7-4), we will create an invoker that contains buttons onto which command objects can be attached. When the button's clicked, the attached command will be executed. The example application will consist of two buttons and a text field. The two buttons will have embedded command objects that will increment and decrement the numerical value in the text field.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial