Mirror (programming)
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. java.lang.Object::getClass() to get a java.lang.Class<?>).
Mirrors adhere to the qualities of encapsulation, stratification and ontological correspondence.[1]
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
- C++, via the
^^operator and the returned typestd::meta::info.[2] - Dart, via its
reflect()function. - Inko,[3] via its
std::mirrormodule. - Rubinius (Ruby implementation), via its
Rubinius::Mirror.reflect()method.[4] - Scala[5]
- Swift, via its
Swift.Mirrorclass and thereflect()function.
See also
References
- ^ Gilad Bracha and David Ungar, "Meta-level Facilities of Object-Oriented Programming languages"
- ^ cppreference.com. "std::meta::info". cppreference.com. Retrieved 19 May 2026.
- ^ "Frequently Asked Questions".
- ^ "Rubinius/Mirror.rb at master · rubinius/Rubinius".
- ^ "Environment, Universes, and Mirrors".
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.