Jump to content

Mirror (programming)

From Wikipedia, the free encyclopedia

This is the current revision of this page, as edited by Citation bot (talk | contribs) at 12:15, 21 September 2021 (Add: title. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by Abductive | Category:Programming paradigms | #UCB_Category 52/113). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In computer programming, 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, 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.[1]

Benefits

[edit]

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

[edit]

References

[edit]
  1. ^ Gilad Bracha and David Ungar, "Meta-level Facilities of Object-Oriented Programming languages"
  2. ^ "Frequently Asked Questions".
  3. ^ "Rubinius/Mirror.rb at master · rubinius/Rubinius".
  4. ^ "Environment, Universes, and Mirrors".