Reflection: Basic Introspection
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
What Definitions Say: Reflection
Reflection is the ability of a program to manipulate as data something representing the state of the program during its own execution.
- Introspection is the ability for a program to observe and therefore reason about its own state.
- Intercession is the ability for a program to modify its own execution state or alter its own interpretation or meaning.
What Definitions Say: Reification
Reification is the process to transform implicit to explicit (objects)
- i.e., getting the stack as an object
- i.e., getting a class as an object
Pharo is a Reflective System
A system having itself as application domain and that is causally connected with this domain can be qualified as a reflective system Maes'87
- A reflective system has an internal representation of itself
- A reflective system is able to act on itself with the ensurance that its representation will be causally connected (i.e. up to date)
Inspector
How does it access internal object state?
State Introspection
Accessing and setting object state
Accessing/Setting State Example
- Violates encapsulation
- But this is for tools and during development
Accessing Class
Querying the System
Querying the System
Sending a Message by its Name
- How to implement a menu or a button?
- Need to send a message to a receiver given a message selector
Sending a Message by its Name
- Asks an object to execute a message
- Normal lookup is performed
Classes Hold Compiled Methods
Executing a Compiled Method
Summary
- Just a part of the reflective power!
- Everything is an object and can be introspected
- Grab objects and talk to them
- Have a look at inspector code
/