Science Fair Projects Ideas - Reflection (computer science)

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Reflection (computer science)

In computer science, reflection is the ability of a program to examine and possibly modify its high level structure at runtime. It is most common in high-level virtual machine programming languages like Smalltalk, and less common in low-level programming languages like C.

When program source code is compiled, information about the structure of the program is normally lost as lower level code (typically assembly language code) is produced. If a system supports reflection, the structure is preserved as metadata with the emitted code.

Known platforms supporting reflection are:

More generally, reflection is an activity in computation that reasons about its own computation. The programming paradigm driven by reflection is called reflective programming.

Implementation

A language supporting reflection provides a number of features available at runtime that would otherwise be very obscure or impossible to accomplish in a lower-level language. Some of these features include:

  • The ability to discover and modify source-code constructions (such as code blocks , classes, methods, protocols, etc.) as first-class objects at runtime.
  • The ability to convert a string matching the symbolic name of a class or function into an invocation of that class or function.
  • The ability to evaluate a string as if it were a source-code statement at runtime.

These features can be implemented in different ways. Interpreted programming languages, such as Ruby and PHP, are ideally suited to reflection, since their source code is never lost in the process of translation to machine language— the interpreter has the source readily available. Complied languages rely on their runtime system to provide information about the source code. A compiled Objective-C executable, for example, records the names of all methods in a block of the executable, providing a table to correspond these with the underlying methods (or selectors for these methods) compiled into the program.

Example

The following is an example in Java. Consider two pieces of code

// Without reflection
Foo foo = new Foo ();
foo.hello ();
// With reflection
Class clazz = Class.forName ("Foo");
Method method = clazz.getMethod ("hello", null);
method.invoke (clazz.newInstance (), null);

The both code creates the instance of a class 'Foo' and calls its method 'hello'. The difference is that in the first piece, the name of the class and the method is hard-coded; it is not possible to use a class of another name. In the second piece, the names of the class and the method can vary at runtime.

(See java.lang.reflect for more of this feature.)

References

  1. Reflection in logic, functional and object-oriented programming: a Short Comparative Study (Citeseer page).
10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice