4 ms·
I'm not a Python developer, but in general metaclasses are classes represented as objects. You can also have objects for methods, attributes, and whatever else
by phaylon 14y ago
I'm not a Python developer, but in general metaclasses are classes represented as objects. You can also have objects for methods, attributes, and whatever else your object system provides. These objects of course also have classes that you can subclass and extend, apply traits to, and so on.
This is very useful for introspection and dynamically building class structures. Which extends to it being also a common API for extensions to your classes (I'm playing with a Perl/Glib project using the Moose MOP framework to allow Perl classes to have Glib signals, for example). Speaking for Perl/Moose, it's regularly used to modify or extend the behavior/capabilities of attributes (by applying traits to them).
Even just the introspective aspect means your program can easily know about the structure of your classes, for serializations, debugging, proxying, auto-generating documentation, auto-generating command line arguments, and so on.
This is just a rough outline, and in no way complete. I'd guess here's a good language-agnostic starting point: http://en.wikipedia.org/wiki/Metaobject http://en.wikipedia.org/wiki/Metaobject
- grifaton 14y agoI'm afriad this doesn't make much sense from a Python point of view, where a metaclass is a very specific language construct. For more details, you can't do much better than the StackOverflow answer that JulianWasTaken has linked to.
- phaylon 14y agoAh, thanks. It seems to be in the same league, but in a different context. Gotta remember that they're different for the future.