Reflection X

Reflection(computer science)
In computer programming, reflection is the ability of a program to examine and possibly modify its high level of internal structures (eg objects) in its execution.

Called reflexivity does for a programming language to enable the writing of such programs. Such a programming language is called reflexive.

Introspection and intercession
There are two techniques used by reflective systems:

* Introspection, which is the ability of a program to examine its own state.
* Intercession, which is the ability of a program to modify its own execution state or alter its own interpretation or meaning.

Introspection is used for measurement of performance, inspect modules or debug a program. It is implemented in languages such as Smalltalk or Java provide tools to know the class of an object, its attributes, methods, etc.. Introspection does not exist in languages like C or Pascal.

Intercession allows a program to automatically change depending on the needs and environment. This property appears in languages like Smalltalk or Python, but it does not exist in languages like C.

Structural reflection and behavioral reflection
Along with concepts of introspection and intercession, there are two types of reflection: reflection structural and behavioral reflection.

The structural reflection is to reify the code of a program and all abstract data types available through this program. In the first case, the reification of the program code to manipulate the program during execution. It is thus possible to maintain a program even when it performs tasks. In the second case, the reification of abstract types allows the program to examine and modify the structure of complex types. It can, for example, develop generic algorithms serialization.

The behavioral reflection (or reflection behavior) relates more particularly the implementation of the program and the program environment. For this type of thinking, a program means to know how it is interpreted and can change its way of being executed, by acting on the data structures of the evaluator and the evaluator himself . Thus, the program can obtain information on its implementation or even self-reorganize to better adapt to an "environment".

Reflection and Object Oriented Programming
In object-oriented programming, reflective architecture is implemented by the concept of metaobject. They represent elements of object-oriented programs such as classes, messages and generic functions. The handling of this metaobject is a metaobject protocol for deciding the behavior of language. CLOS is the first language to have implemented a meta-object protocol.

Read also