Varieties of Lookup

In CHAIN OF RESPONSIBILITY, an object model takes on the job of finding which object can satisfy a client's request. This approach goes beyond the two lookup mechanisms that are built into Java: exception handling and method lookup.

When an exception is thrown, the Java interpreter looks back up the call stack to find a method called from a block enclosed in a try/catch statement. If this try/catch statement does not catch an exception of the type thrown, the Java interpreter keeps looking. This can propagate up to the main() method. If the exception is not handled there, the Java interpreter prints out an error message and stack trace and then exits.

The more common case of lookup in Java is method lookup—the algorithm for ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.