Difference between revisions of "Multi-Paradigm Programming and Scripting"

From Sinfronteras
Jump to: navigation, search
(Reflection in Java)
Line 35: Line 35:
  
 
'''Uses of reflection for software tools:'''
 
'''Uses of reflection for software tools:'''
 
 
*Class browsers need to enumerate the classes of a program
 
*Class browsers need to enumerate the classes of a program
 
*Visual IDEs use type information to assist the developer in building type correct code
 
*Visual IDEs use type information to assist the developer in building type correct code
 
*Debuggers need to examine private fields and methods of  classes
 
*Debuggers need to examine private fields and methods of  classes
 
*Test systems need to know all of the methods of a class
 
*Test systems need to know all of the methods of a class
 +
 +
 +
'''Downsides of Reflection:'''
 +
* Performance costs
 +
* Exposes private fields and methods
 +
* Voids the advantages of early type checking
 +
* Some reflection code may not run under a security manager, making code nonportable
  
  

Revision as of 20:41, 30 October 2019

  • Improved background for choosing appropriate languages



Compilation vs Interpretation


Phases of Compilation

Phases of compilation.png



C++ Inheritance

https://www.w3schools.com/cpp/cpp_inheritance.asp

https://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm



Difference Between Static and Dynamic Binding

https://techdifferences.com/difference-between-static-and-dynamic-binding.html



Reflection in Java

A programming language that supports reflection allows its programs to have runtime access to their types and structure and to be able to dynamically modify their behavior

  • The types and structure of a program are called metadata
  • The process of a program examining its metadata is called introspection
  • Interceding in the execution of a program is called intercession


Uses of reflection for software tools:

  • Class browsers need to enumerate the classes of a program
  • Visual IDEs use type information to assist the developer in building type correct code
  • Debuggers need to examine private fields and methods of classes
  • Test systems need to know all of the methods of a class


Downsides of Reflection:

  • Performance costs
  • Exposes private fields and methods
  • Voids the advantages of early type checking
  • Some reflection code may not run under a security manager, making code nonportable



Reflection in Java

  • Limited support from java.lang.Class
  • Java runtime instantiates an instance of Class for each object in the program
  • The getClass method of Class returns the Class object of an object
float[] totals = new float[100];
Class fltlist = totals.getClass();
Class stg = "hello".getClass();
  • If there is no object, use class field:
Class stg = String.class;
  • Class has four useful methods:
getMethod searches for a specific public method of a class
getMethods returns an array of all public methods of a class
getDeclaredMethod searches for a specific method of a class
getDeclaredMethods returns an array of all methods of a class
The Method class defines the invoke method, which is used to execute the method found by getMethod