Design Patterns / Week 9

User operationsUser Operations

Now, it’s interactivity time! End-users need to interact with the system in order to accomplish various tasks. They need to open, edit, check, save or print their documents. They need to input data in the system. In a GUI, there are many points of interaction, like menus, keyboard shortcuts or toolbar buttons. For example, the menu item Open from File menu, the shortcut Ctrl-O and the button Open from the toolbar, all trigger the same operation: shows up the File Open dialog box that allow users to select the working document. From this example, it stands out that we need to decouple the triggering of an operation from the execution of that operation in order to have the same behavior regardless the triggering source. The Command pattern is doing a great job here.

A special editing feature needs a little bit more consideration at this point: Undo / Redo. It helps us to easily recover from errors, or to change our mind easily. Isn’t that great 🙂 In order to be able to go back and forth from one state to another, the system needs to store its state before executing a particular operation / action. Memento pattern helps us to achieve this. In the same time, we need to extend Command class with a new member function, Unexecute, that will be called during Undo operation.

What about if there are more objects in the same able to handle a request? How to select the most suitable one? Chain of Responsibility pattern offers an extensible solution for this purpose.

More details about supporting user operations are available in this week’s lecture handouts.

This entry was posted in Design Patterns and tagged , , , , . Bookmark the permalink.