In object-oriented computer programming, a metaclass is one whose instances are also classes. For instance, in Python, the built-in class type is a metaclass: instances of class type are themselves a class of objects.
The use of metaclasses is most prevalent in object-oriented languages. In these languages, classes are “first-class” objects, meaning they can be used exactly like any other object in the language.
- They can be named variables.
- They can be passed as an argument to methods, functions, and procedures.
- They can be returned as the result of a method, function, or procedure.
- They can be included as part of a data structure.
It is possible, but uncommon, to implement metaclasses in C++ and Java. More commonly, metaclasses are found in programs written in Python, Ruby, Smalltalk, Perl, Objective-C, and Common Lisp/CLOS.
Object-oriented, Programming, Programming terms