Reflection




Michal P´se (CTU in Prague)
        ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   2 / 10
Terminology




     Introspection—self-representation can be queried.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   3 / 10
Terminology




     Introspection—self-representation can be queried.
     Intercession—self-representation can be changed.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   3 / 10
Terminology (II)




     Structural reflection—concerned with structure.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   4 / 10
Terminology (II)




     Structural reflection—concerned with structure.
     Behavioral reflection—concerned with execution.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   4 / 10
Reflection in Object Languages




Everything is an object.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   5 / 10
Purpose




Tools.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   6 / 10
Alternative




      Source code
      Byte code
      AST
      Custom represenation




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   7 / 10
Metadata




Michal P´se (CTU in Prague)
        ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   8 / 10
What Is Metadata?




     Field and method names




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   9 / 10
What Is Metadata?




     Field and method names
     Class names




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   9 / 10
What Is Metadata?




     Field and method names
     Class names
     Various modifiers




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   9 / 10
What Is Metadata?




     Field and method names
     Class names
     Various modifiers
     Even type information




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   9 / 10
What Is Metadata?




     Field and method names
     Class names
     Various modifiers
     Even type information
     More or less anything that is not compiled into binary




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and Metadata December 14, 2010   9 / 10
Is Metadata Used Outside of Source Code?




     Yes




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and MetadataDecember 14, 2010   10 / 10
Is Metadata Used Outside of Source Code?




     Yes
     Whenever we are referring to a class we are supplying it with an
     additional information




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and MetadataDecember 14, 2010   10 / 10
Is Metadata Used Outside of Source Code?




     Yes
     Whenever we are referring to a class we are supplying it with an
     additional information
     Why don’t we include metadata in the source code? Is it possible?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 12: Reflection and MetadataDecember 14, 2010   10 / 10

Reflection and Metadata

  • 2.
    Reflection Michal P´se (CTUin Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 2 / 10
  • 3.
    Terminology Introspection—self-representation can be queried. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 3 / 10
  • 4.
    Terminology Introspection—self-representation can be queried. Intercession—self-representation can be changed. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 3 / 10
  • 5.
    Terminology (II) Structural reflection—concerned with structure. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 4 / 10
  • 6.
    Terminology (II) Structural reflection—concerned with structure. Behavioral reflection—concerned with execution. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 4 / 10
  • 7.
    Reflection in ObjectLanguages Everything is an object. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 5 / 10
  • 8.
    Purpose Tools. MichalP´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 6 / 10
  • 9.
    Alternative Source code Byte code AST Custom represenation Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 7 / 10
  • 10.
    Metadata Michal P´se (CTUin Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 8 / 10
  • 11.
    What Is Metadata? Field and method names Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 9 / 10
  • 12.
    What Is Metadata? Field and method names Class names Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 9 / 10
  • 13.
    What Is Metadata? Field and method names Class names Various modifiers Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 9 / 10
  • 14.
    What Is Metadata? Field and method names Class names Various modifiers Even type information Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 9 / 10
  • 15.
    What Is Metadata? Field and method names Class names Various modifiers Even type information More or less anything that is not compiled into binary Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and Metadata December 14, 2010 9 / 10
  • 16.
    Is Metadata UsedOutside of Source Code? Yes Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and MetadataDecember 14, 2010 10 / 10
  • 17.
    Is Metadata UsedOutside of Source Code? Yes Whenever we are referring to a class we are supplying it with an additional information Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and MetadataDecember 14, 2010 10 / 10
  • 18.
    Is Metadata UsedOutside of Source Code? Yes Whenever we are referring to a class we are supplying it with an additional information Why don’t we include metadata in the source code? Is it possible? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 12: Reflection and MetadataDecember 14, 2010 10 / 10