HOME

TheInfoList



OR:

In
computer programming Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, a mirror is a reflection mechanism that is completely decoupled from the object whose structure is being introspected. This is as opposed to traditional reflection, for example in
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, where one introspects an object using methods from the object itself (e.g. getClass()). Mirrors adhere to the qualities of encapsulation, stratification and ontological correspondence.


Benefits

Decoupling the reflection mechanism from the objects themselves allows for a few benefits: * The object's interface is not polluted, so there is no danger of breaking reflection by overriding a reflective method. * There can be different mirror systems. * The mirror system can be removed entirely (potentially allowing for optimizations). * A mirror system can operate on remote code, since it is not coupled with a particular machine.


Languages that use mirrors

* Dart, via its ''reflect'' function. * Inko, via its ''std::mirror'' module. *
Rubinius Rubinius is an alternative Ruby implementation created by Evan Phoenix. Based loosely on the Smalltalk-80 ''Blue Book'' design, Rubinius seeks to "provide a rich, high-performance environment for running Ruby code." Goals Rubinius follows in t ...
(
Ruby Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
implementation), via its ''Rubinius::Mirror.reflect'' method. * Scala *
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIF ...
, via its ''reflect'' function.


References

Programming paradigms {{comp-sci-stub