CSC/ECE 517 Fall 2011/ch4 4f rs

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Reflection is a relatively common computer programming concept where in the program has the inherant ability to examine itself at runtime. Based on its observations the program can modify it's behaviour for the given situation.The modifications can be any aspect of the programming language .i.e syntax, semantics, or implementation.

Reflection as a concept was first introduced in the doctoral dissertation of Dr. Brian Cantwell Smith in 1992.

Reflection

Reflection is the ability of a program or a computation to examine and modify itself at run time even though it does not have enough information at compile time. For example in a high level object oriented language the ability to inspect its class , interfaces and methods at run time without knowing their names at compile time. It also provides the ability to modify , instantiate and access to methods such as getter's and setter's of a class.

Implementation

There are many challenges faced by designers of reflective languages. They must provide as much leeway as possible for late binging and at the same time they must optimize the compilation of the static components so that they are ready for run-time. Some of the critical components required for implementing reflection is as follows:

1. Ability to create first class objects(http://en.wikipedia.org/wiki/First-class_object) ie reification (http://en.wikipedia.org/wiki/Reification_(computer_science)).

2. Ability to convert a string that denotes a class or a method into its corresponding reference or invocation.

3. Ability to use and create symbolic links to methods and classes.

Reflection by example

Applications of Reflection

Advantages and disadvantages of refletion

Additional Reading