OTCL的多继承

 1 Class Thing
 2 Class Animal
 3 Class Other -superclass {Animal Thing}
 4 
 5 Thing instproc init {args} {
 6         puts "here is init from:thing"
 7         eval $self next $args
 8 }
 9 Thing instproc move {} {
10         puts "here is move from:thing"
11 }
12 
13 Animal instproc init {args} {
14         puts "here is init from:animal"
15         eval $self next $args
16 }
17 Animal instproc move {} {
18         puts "here is move from:animal"
19         eval $self next
20 }
21 
22 Other instproc init {args} {
23         puts "here is init from:other"
24         eval $self next $args
25 }
26 Other instproc move {} {
27         puts "here is move from:other"
28         eval $self next 
29 }
30 Other other
31 other move

输出:

here is init from:other
here is init from:animal
here is init from:thing
here is move from:other
here is move from:animal
here is move from:thing

上面是简单地继承两个父类,在调用next的时候,顺序是按继承时候的从左到右的顺序,依次调用。

如果是这样:

Class theOne
Class Thing -superclass theOne
Class Animal
Class Other -superclass {Thing Animal}

theOne instproc init {args} {
        puts "here is init from:theOne"
        eval $self next $args
}
theOne instproc move {} {
        puts "here is move from:theOne"
        eval $self next 
}

Thing instproc init {args} {
        puts "here is init from:thing"
        eval $self next $args
}
Thing instproc move {} {
        puts "here is move from:thing"
        eval $self next 
}

Animal instproc init {args} {
        puts "here is init from:animal"
        eval $self next $args
}
Animal instproc move {} {
        puts "here is move from:animal"
        eval $self next
}

Other instproc init {args} {
        puts "here is init from:other"
        eval $self next $args
}
Other instproc move {} {
        puts "here is move from:other"
        eval $self next 
}
Other other
other move

输出:

here is init from:other
here is init from:thing
here is init from:theOne
here is init from:animal
here is move from:other
here is move from:thing
here is move from:theOne
here is move from:animal
原文地址:https://www.cnblogs.com/lunac/p/3397960.html