Chapter 25
Reflection and Introspection
The terms reflection and introspection refer to the ability of a program during execution to “learn” something about itself. The first term suggests the mental image of a program examining itself in a mirror, which is a useful metaphor. The mechanisms for reflection allow the program to examine its own internal state in more detail than is possible in languages that do not have reflection facilities. In some languages, the program can even add new behavior to itself as it is executing.
We can divide the mechanisms used in reflection and introspection into two broad categories. The first group are features designed to gain understanding concerning the current state of computation. These mechanisms yield ...
Get An Introduction to Object-Oriented Programming, 3rd Edition 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.