Version 8 of oo::define

Updated 2017-12-12 13:44:36 by pooryorick

oo::define , a built-in Tcl command, defines and changes the definition of existing classes in TclOO.

Synopsis

oo::define class definitionScript
oo::define class arg arg ?arg ...?

If given as a sequence of args, the definitionScript is created by making a list of those arguments and evaluating that as if it was given as a definitionScript. Supported definitions for use in the definitionScript are:

constructor argList bodyScript
deletemethod name ?name ...?
destructor bodyScript
export name ?name ...?
filter ?methodName ...?
forward name cmdName ?arg ...?
method name argList bodyScript
mixin ?className ...?
renamemethod fromName toName
self subcommand arg ...
self script
superclass className ?className ...?
unexport name ?name ...?
variable ?name ...?

Documentation

official reference

forward

my can be used as the command name:

oo::objdefine myobject forward method2 my method1 

Precursors, Methods, and Exports

PYK 2017-12-12:

The act of creating a new method resets the current export setting for the method. In the following example, it is necessary to use export twice in order for the invocation of .~ to succeed.

oo::class create c1 {
    method .~ {} {
        puts {c1 method}
    }
    export .~
}

oo::class create c2 {
    superclass c1
    method .~ {} {
        puts {c2 method}
    }
    export .~
}

c2 create obj1
obj1 .~