Web server - 792 Graphical User Interface Components: Part 2 Chapter
792 Graphical User Interface Components: Part 2 Chapter 13 13.18.3 Behavioral Design Patterns In this section, we continue our discussion on behavioral design patterns. We discuss the Chain-of-Responsibility, Command, Observer, Strategy and Template Method design patterns. Chain-of-Responsibility In object-oriented systems, objects interact by sending messages to one another. Often, a system needs to determine at run time the object that will handle a particular message. For example, consider the design of a three-line office phone system. When a person calls the office, the first line handles the call if the first line is busy, the second line handles the call, and if the second line is busy, the third line handles the call. If all lines in the system are busy, an automated speaker instructs that person to wait for the next available line when a line becomes available, that line handles the call. The Chain-of-Responsibility design pattern enables a system to determine at run time the object that will handle a message. This pattern allows an object to send a message to several objects in a chain of objects. Each object in the chain either may handle the message or pass the message to the next object in the chain. For instance, the first line in the phone system is the first object in the chain of responsibility, the second line is the second object, the third line is the third object, and the automated speaker is the fourth object. Note that this mechanism is not the final object in the chain the next available line handles the message, and that line is the final object in the chain. The chain is created dynamically in response to the presence or absence of specific message handlers. Several Java AWT GUI components use the Chain-of-Responsibility design pattern to handle certain events. For example, class java.awt.Button overrides method processEvent of class java.awt.Component to process AWTEvent objects. Method processEvent attempts to handle the AWTEvent upon receiving this event as an argument. If method processEvent determines that the AWTEvent is an ActionEvent (i.e., the Button has been pressed), the method handles the event by invoking method processActionEvent, which informs any ActionListener registered with the Button that the Button has been pressed. If method processEvent determines that the AWTEvent is not an ActionEvent, the method is unable to handle the event and passes the AWTEvent to method processEvent of superclass Component (the next object in the chain). Command Applications often provide users with several ways to perform a given task. For example, in a word processor there might be an Edit menu with menu items for cutting, copying and pasting text. There could also be a toolbar and/or a popup menu offering the same items. The functionality the application provides is the same in each case the different interface components for invoking the functionality are provided for the user’s convenience. However, the same GUI component instance (e.g., JButton) cannot be used for menus and toolbars and popup menus, so the developer must code the same functionality three times. If there were many such interface items, repeating this functionality would become tedious and error-prone. The Command design pattern solves this problem by enabling developers to specify the desired functionality (e.g., copying text) once in a reusable object; that functionality can
Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services