5 ms·
Anyone want to explain meta classes for me? Without knowing anything from the start, I would think that they are some subset of classes, maybe they inherit from
by rodriguezcommaj 14y ago
Anyone want to explain meta classes for me? Without knowing anything from the start, I would think that they are some subset of classes, maybe they inherit from some built-in classes in Python? I'm somewhat familiar with what classes are - a defined object that has certain characteristics that describe it and store information about it, as well as methods that can be used on that object. I always think of a rocketship class that might have a size, color, velocity, health, fuel, etc. and then have methods like accelerate, decelerate, rotate, shoot, etc. How do meta classes differ?
- JulianWasTaken 14y agoA metaclass is simply the class of a class. Rather than elaborating on that, there's a stack overflow answer that's often linked that is uncharacteristically decent at explaining here: http://stackoverflow.com/a/6581949/637787 http://stackoverflow.com/a/6581949/637787. Note that as I said, I would suggest you completely ignore this and not even bother reading that right now.
- phaylon 14y agoI'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.