Meta Class

A MetaClass 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 CommonLispObjectSystem) is; one cannot do MetaObjectProtocol stuff in JavaLanguage. 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 SmalltalkLanguage point of view, JavaLanguage isn't fully object oriented, nor is CsharpLanguage nor CeePlusPlus. 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 AspectOrientedProgramming.


DavidMertz and Michele Simionato have written a couple very clear papers about MetaClass programming in PythonLanguage (http://gnosis.cx/publish/tech_index_dw.html).


CategoryAspectOrientation


EditText of this page (last edited November 20, 2014) or FindPage with title or text search