Information Technology Reference
In-Depth Information
In the preceding class diagram, we can see that the
addTask
method is translated to a
command invocation as follows:
public void addTask(Task task) {
Command<Void> cmd = new AddTaskCommand(task);
return commandService.execute(cmd);
}
A similar structure is followed for every single method invocation in the task service API.
As you can see, the
commandService.execute()
method invocation will be the
one done for every method.
The next step to understand the interceptors is to understand the
CommandService
class. This class will have the responsibility of invoking the actual
execute
method in
the
Command
object. The idea behind the interceptors is that you can decorate the class
by creating wrappers for it. Each one of the wrappers can invoke special pieces of code
before and/or after the method invocation. The result is the creation of different compon-
ents that can do anything you want before or after every method that is called on top of
the task service.