Skip to main content
gamedev.net
🔒 Locked

reflection

Started by ChaosEngine Apr 28, 2004 at 12:47 AM 2 replies 600+ views
Original Post
ChaosEngine
ChaosEngine
There's been a lot of talk on these here forums lately about reflection. Now the term tickles some neurons in the back of the 'ol skull, but I'm damned if I can remember exactly what it is. Having briefly googled and found too much info, I was hoping some enlightened person would favour me with a simple explanation. Go on, you know you want to..... I'll even look into learning LISP if someone explains this. "That's not a bug, it's a feature!" --me [edited by - ChaosEngine on April 28, 2004 1:48:18 AM]
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
Zipster
Zipster
Simply put, reflection allows you to access information about assemblies (in the .NET context) and types as well as create, invoke, and access them all at run-time. This is good for things like scripting languages, where you wouldn't actually be interpreting the scripts until run-time and thus won't know what types to create or methods to invoke. A few languages support reflection, but unfortunately vanilla C++ isn't one of them.

MSDN has a quick and dirty rundown on using reflection under the .NET Framework SDK. It's worth a look. Java also has a nifty reflection API.

[edited by - Zipster on April 28, 2004 2:05:52 AM]
antareus
antareus
You can do cool things like imbue classes with serialization support without actually writing the serialization code, like a mix-in class. It would merely enumerate all of the properties of the object and serialize them to disk.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Zahlman
Zahlman
In Java, reflection is useful mainly for doing things like loading classes (and instantiating instances thereof) given their names - this might be useful for e.g. soft configuration of things from a file. Say you have a couple hundred tiny classes that implement a Command pattern, and you want to have a configuration file that indicates which commands may be used the next time the code is run (maybe you want to disable some for security reasons), or provide some other metadata - you would be able to just put the class names in the file, and your code could parse Strings out of the file and that would be enough information to load the instances.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.