Meta Class

A Meta Class is a object that describes a class.

object = new Object() clazz = object.class metaclass = clazz.class // The Class class : "[Metaclasses] are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don't (the people who actually need them know with certainty that they need them, and don't need an explanation about why)." -- TimPeters

Others might say a language without metaclasses is broken, and not really object oriented!


There are lots of good OO languages without metaclasses. While certainly useful, they aren't absolutely necessary--and many programming tasks can get by without them. Regarding java.lang.Class; it certainly isn't a metaclass in the sense that standard-class (from Common Lisp Object System) is; one cannot do Meta Object Protocol stuff in Java Language. OTOH, java.lang.Class is a first-class object, and it does provide introspection capabilities on classes in Java.

As I said, others "might" say a language without metaclasses is broken, and not really object oriented. I was referring to Smalltalkers of course. From the Smalltalk Language point of view, Java Language isn't fully object oriented, nor is Csharp Language nor Cee Plus Plus. Java.lang.Class is a first class object that you can't change; it's equivalent to C#'s Type class, and while useful, isn't a metaclass. For example, a real metaclass would allow me to change method lookup to allow Aspect Oriented Programming.


David Mertz and Michele Simionato have written a couple very clear papers about Meta Class programming in Python Language (gnosis.cx ).


See original on c2.com