Version 5 of metaclass

Updated 2014-12-28 14:57:37 by dkf

Metaclasses are classes that are subclasses of the class of classes. Supported by TclOO and XOTcl. Can be used to do really quite fundamental changes to the way classes work.

LV weird - normally, I would think of a meta class as being something above (and outside) something else, handling information about the something else. Or maybe it is the term subclass that threw me - what does subclass of the class of classes mean?

So, what kinds of really quite fundamental changes can be done with metaclasses in tcloo and xotcl? And are there similar concepts in other tcl based object oriented extensions?

DKF: I don't know. I know that you can't do it with [incr Tcl]; classes aren't (traditionally) objects there. To my mind, the main use for a metaclass is to change the way in which you create a class. Thus, with TclOO you can do this to create something with a much more XOTcl-like feel:

oo::class create Class {
    superclass oo::class
    method constructor {argList body} {
        ::oo::define [self] constructor $argList $body
    }
    method destructor {body} {
        ::oo::define [self] destructor $body
    }
    method filter {args} {
        ::oo::define [self] filter {*}$args
    }
    method forward {name cmdName args} {
        ::oo::define [self] forward $name $cmdName {*}$args
    }
    method method {name argList body} {
        ::oo::define [self] method $name $argList $body
    }
    method mixin {args} {
        ::oo::define [self] mixin {*}$args
    }
    method superclass {args} {
        ::oo::define [self] superclass {*}$args
    }
    method variable {args} {
        ::oo::define [self] variable {*}$args
    }
}