Use-cases for reflection

后端 未结 9 2148
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 20:34

Recently I was talking to a co-worker about C++ and lamented that there was no way to take a string with the name of a class field and extract the field with that name; in o

9条回答
  •  情歌与酒
    2020-12-08 20:56

    I can list following usage for reflection:

    • Late binding
    • Security (introspect code for security reasons)
    • Code analysis
    • Dynamic typing (duck typing is not possible without reflection)
    • Metaprogramming

    Some real-world usages of reflection from my personal experience:

    • Developed plugin system based on reflection
    • Used aspect-oriented programming model
    • Performed static code analysis
    • Used various Dependency Injection frameworks
    • ...

    Reflection is good thing :)

提交回复
热议问题