I have a friend who is interested in getting into programming and is asking about a lot of different concepts. Classes, interfaces and things like polymorphism / inheritence have been easy to explain, but I’m struggling a bit with analogies for reflection.
How would you explain what it is and how it works in practice?
Reflection is simply the ability of an object to tell you about itself, its methods, instance variable, type etc. To use the metaphor its named after its like looking in a mirror and seeing yourself. In that way you can describe yourself to someone else. In the same way reflection is the ability for an object (or even program) to describe itself.