next up previous

9.5.3 Shadowed Message-handlers

When one handler must be called by another handler in order to be executed, the first handler is said to be shadowed by the second. An around handler shadows all handlers except more specific around handlers. A primary handler shadows all more general primary handlers.

Messages should be implemented using the declarative technique, if possible. Only the handler roles will dictate which handlers get executed; only before and after handlers and the most specific primary handler are used. This allows each handler for a message to be completely independent of the other message-handlers. However, if around handlers or shadowed primary handlers are necessary, then the handlers must explicitly take part in the message dispatch by calling other handlers they are shadowing. This is called the imperativetechnique. The functions call-next-handler and override-next-handler (see section 12.16.2) allow a handler to execute the handler it is shadowing. A handler can call the same shadowed handler multiple times.

Example

(defmessage-handler USER my-message around ()
 (call-next-handler))
(defmessage-handler USER my-message before ())
(defmessage-handler USER my-message ()
 (call-next-handler))
(defmessage-handler USER my-message after ())
(defmessage-handler OBJECT my-message around ()
 (call-next-handler))
(defmessage-handler OBJECT my-message before ())
(defmessage-handler OBJECT my-message ())
(defmessage-handler OBJECT my-message after ())

For a message sent to an instance of a class which inherits
from USER, the diagram to the right illustrates the order
of execution for the handlers attached to the classes USER
and OBJECT. The brackets indicate where a particular
handler begins and ends execution. Handlers enclosed within
a bracket are shadowed.




next up previous