How would you explain reflection to a non-programmer?

I have a friend who is interested in programming and asks about many different concepts. Classes, interfaces, and things like polymorphism / inheritance are easy to explain, but I'm struggling a bit with peers for thought.

How would you explain what it is and how it works in practice?

+3
source share
7 answers

Reflection is simply the ability of an object to tell you about itself, its methods, instance variable, type, etc. To use a metaphor, she was named by name, for example, looking in a mirror and seeing herself. That way you can describe yourself as someone else. Similarly, reflection is the ability of an object (or even program) to describe itself.

+19

" - ( ). , ."

?

Edit: , , . , . , ..

+3

. - , . , , .

, . , , , , , .

+3

, . - . , ...

+1

, - . , :

  • .

:

  • ()
  • ()
  • .

, ( ), . . . . , . ...

, , /.

+1

, Python, , ; .. , , , .

0

, , . . , ; abject, .

. , . , , - . , .

Instead of (misleading) analogues, what about some illustrative uses? Reflection is an easy way to implement one of the central tasks of the debugger: examining objects stored in variables. Saving and retrieving objects from an external data warehouse is made easier with reflection, because you do not need to write a serializer for each class. The universal serializer can instead use reflection to examine the properties of an object and use it to create a database schema.

0
source

Source: https://habr.com/ru/post/1713484/


All Articles