Posted to tcl by apw at Mon Sep 10 13:21:00 GMT 2007view pretty

package require Itcl 4.0

::itcl::class Person {
private variable nbPersons 0
protected variable name
protected variable tool
constructor {{myname "Steve McQueen"}} {
    set name $myname
    incr nbPersons
    puts "Person named : '$name' created"
}
destructor {
    incr nbPersons -1
    puts "Person named : '$name' deleted"
}

}

::itcl::class Tool {
method tell {message} {
    return "Tool is telling you : '$message'"
}
method sing {who what} {
    return "$who sings : '$what'"
}
}

set t [Person #auto "Steve McQueen"]
::itcl::mixin add ::Person ::Tool
::itcl::forward add $t singing $t sing "Queen"
puts [$t tell "This is the truth : I am a liar"]
puts [$t singing "We will rock you!"]
:::itcl::delete object $t

Result in both versions:

Person named : 'Steve McQueen' created
Tool is telling you : 'This is the truth : I am a liar'
Queen sings : 'We will rock you!'
Person named : 'Steve McQueen' deleted