Reflection is a programming language feature that allows a program to examine and modify its own structure and behavior during runtime. It enables inspecting and modifying objects and classes dynamically.
- Provides metadata to adapt the system dynamically at runtime
- Meta-level makes the system self-aware
- Base level contains business logic
Usage
- CLOS - Uses reflection for generic functions.
- CORBA - Reflection enables dynamic invocations.
Benefits
- Adaptability - Can modify structure and behavior dynamically.
- Language independence - Mechanism does not depend on languages.
Drawbacks
- Instability - Metadata changes can corrupt behavior.
- Debugging difficulty - Hard to track meta-level changes.
- Performance overhead - Meta-object protocols add overhead.
Example
In some programming languages like Java or C#, reflection allows examining the properties and methods of objects dynamically, enabling tasks like dynamic loading of classes or generating code at runtime.