Controller GRASP Pattern
Controller is the GRAS Patterns (General Responsibility Assignment Software Pattern)
For example, when a writer using a word processor presses the "spell check" button, he is generating a system event indicating "perform a spell check."
A Controller is a non-user interface object responsible for receiving or handling a system event. A Controller defines the method for the system operation.
Who should be responsible for handling an input event, which object/s beyond the UI layer receives interaction?
Corollary: Note that "window," "applet," "widget," "view," and "document" classes are not on this list. Such classes should not fulfill the tasks associated with system events, they typically receive these events and delegate them to a controller.
Read about GRASP Patterns: GRASP Patterns Overview
Problem
Who should be responsible for handling an input system event?
An input system event is an event generated by an external actor. They are associated with system operations of the system in response to system events, just as messages and methods are related.For example, when a writer using a word processor presses the "spell check" button, he is generating a system event indicating "perform a spell check."
A Controller is a non-user interface object responsible for receiving or handling a system event. A Controller defines the method for the system operation.
Who should be responsible for handling an input event, which object/s beyond the UI layer receives interaction?
Solution
Assign the responsibility for receiving or handling a system event message to a class representing one of the following choices:- Represents the overall system, device, or subsystem (facade controller).
- Represents a use case scenario within which the system event occurs, often named <UseCaseName>Handler, <UseCaseName>Coordinator, or <Use-CaseName>Session (use-case or session controller).
- Use the same controller class for all system events in the same use case scenario.
- Informally, a session is an instance of a conversation with an actor. Sessions can be of any length but are often organized in terms of use cases (use case sessions).
Corollary: Note that "window," "applet," "widget," "view," and "document" classes are not on this list. Such classes should not fulfill the tasks associated with system events, they typically receive these events and delegate them to a controller.
Example
Benefits
- Either the UI classes or the problem/software domain classes can change without affecting the other side.
- The controller is a simple class that mediates between the UI and problem domain classes, just forwards
- event handling requests
- output requests
Comments
Post a Comment