theLib 10.0
Loading...
Searching...
No Matches
compare 'myoo' with 'tcloo'

Class

what myoo tcloo
load the package
package require libmyoox
package require TclOO
philosophy
  • myoo is inspired by Python.
  • When calling a method, the SELF pointer is always the first argument.
  • The method is always executed in the class-namespace.
  • tcloo borrows many concepts from XOTcl,
  • so there's definite continuity from Smalltalk in there.
  • The method is always executed in the object-namespace.
define a class
myooX::ClassN ::ClassName { ... }
oo::class create ClassName { ... }
add super-class
myooX::SuperN ::MyClass MySuper
oo::define MyClass superclass MySuper
update class after change
myooX::RecompileN ::MyClass
once after all changes were done.
NOT REQUIRED
basic usage
myooX::ClassN ::MyClass ?defScript?
namespace eval MyClass arg ?arg ...?
proc MyClass::MyMethod { ?myNs? ... } { ... }
oo::define MyClass defScript
oo::define MyClass subcommand arg ?arg ...?
oo::objdefine object defScript
oo::objdefine object subcommand arg ?arg ...?
basic usage - namespace
 
# myoo uses the CLASS namespace

# class namespace
myooX::ClassN ::baseC {
  # define "public" method
  namespace export {[a-z]*}
  # instance method
  proc bse  { myns } { namespace current }
}
> ::baseC
myooX::ClassN ::testC {
  SuperI ::baseC
  # instance method
  proc mth  { myNs } { namespace current }
  # class method
  proc smth {      } { namespace current }
}
> ::testC

set test1 [myooX::NewN ::testC]
> ::testC::testC-1

# instance method namespace
testC::mth $test1
> ::testC
# instance method base namespace
testC::bse $test1
> ::baseC
# class method namespace
testC::smth
> ::testC
 
 
# tcloo uses the OBJECT namespace

# class namespace
oo::class create baseC {
  # instance method
       method bse  {} { namespace current }
}
> ::baseC
oo::class create testC {
  superclass baseC
  # instance method
       method mth  {} { namespace current }
  # class method
  self method smth {} { namespace current }
}
> ::testC

set test1 [testC new]
> ::oo::Obj23

# instance method namespace
$test1 mth
> ::oo::Obj23
# instance method base namespace
$test1 bse
> ::oo::Obj23
# class method namespace
testC smth
> ::oo::Obj22
 

Method

what myoo tcloo
add class-method
proc MyClass::MyMethod { ... } { ... }
oo::define MyClass self MyMethod { ... } { ... }
add instance-method
proc MyClass::MyMethod { myNs ... } { ... }
oo::define MyClass MyMethod { ... } { ... }
add constructor
proc MyClass::MyClass { myNs ... } { ... }
oo::define MyClass constructor { ... } { ... }
add destructor
proc MyClass::~MyClass { myNs } { ... }
oo::define MyClass destructor { ... }
mark method-as-public
namespace eval MyClass { namespace export PATTERN }
oo::define MyClass export MyMethod1 ?MyMethodX ...?
delete a method
rename MyClass::MyMethod ""
oo::define MyClass deletemethod MyMethod1 ?MyMethodX ...?
rename a method
rename MyClass::MyMethod MyClass::MyNewMethod
oo::define MyClass renamemethod MyMethod MyNewMethod
add a object-method
proc ${MyNs}::MyClass { myNs ... } { ... }
oo::objdefine MyObject method { ... } { ... }

Variable

what myoo tcloo
add/use a class-variable
proc MyClass::MyMethod { ... } {
variable MyClassVariable
}
???
add/use a instance-variable
proc MyClass::MyMethod { myNs ... } {
namespace upvar $myNs my my
.. $my(InstanceVariable) ..
}
oo::define MyClass method MyMethod { ... } {
variable MyInstanceVariable
.. $MyInstanceVariable ..
}
add/use a private-instance-variable
proc MyClass::MyMethod { myNs ... } {
namespace upvar $myNs MyPrivateInstanceVariable MyPrivateInstanceVariable
.. $MyPrivateInstanceVariable ..
}
???
define a instance-variable in the class definition
NOT POSSIBLE
variable MyVariable1 ?MyVariableX ...?

Create & Delete

what myoo tcloo
create an anonymous-instance
myooX::NewN MyClass ?arg ...?
myooX::Create1N MyClass ?arg ...?
MyClass new ?arg ...?
create a named-instance
myooX::Create2N MyClass MyInstance ?arg ...?
myooX::Create3N MyClass MyInstance MyNs ?arg ...?
MyClass create MyInstance ?arg ...?
delete a named-instance
myooX::DestroyN MyInstance
MyInstance destroy