Some languages like Dart use mirror based reflection so, in simple terms, what is the difference between such implementation and traditional reflection as you see in C# or Java.
Update: I found this excellent (and somewhat quirky) video by Gilad Bracha on Mirror based reflection in Newspeak. http://www.hpi.uni-potsdam.de/hirschfeld/events/past/media/100105_Bracha_2010_LinguisticReflectionViaMirrors_HPI.mp4 (mirror stuff starts at 7:42)
A mirror is a piece of furniture people have in their houses, usually the bathroom, it shows their reflection. An example is, every day I wake up and look in the mirror and see myself. Reflect/reflection is when you can see you self in something as the light is bouncing off the object and back at you.
You look into the mirror and see your own face inside the mirror. What you see is a reflection of your face in the mirror. We also see reflections of other objects that are in front of the mirror. An image can be seen in the mirror because the light reflected from an object falls on the mirror and it is reflected.
The main difference between the brick wall and a mirror is the flatness of the surface. The morphology of the surface will determine whether you will observe specular or diffuse reflection.
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() ).
For many uses, I don't think mirrors will be that different than Java reflection. The most important thing understand about mirrors is that they decouple the reflection API from the standard object API, so instead of obj.getClass() you use reflect(obj). It's a seemingly small difference, but it gives you a few nice things:
Here's how mirrors are different than reflection in Java and Javascript when used to get an object's methods:
Java:
myObject.getClass().getMethods(); // returns an array
Dart:
reflect(myObject).type.methods; // returns a map
Javascript:
var methods = [];
for (var m in myObject) {
if (typeof m === 'function') {
methods.push(m);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With