Overview
| Artifact ID: | 479011423863fdc476c4f8fe2dbe265c80dfa6af |
|---|---|
| Ticket: | 3474460fffffffffffffffffffffffffffffffff
targetObject should be optional for oo::copy |
| User & Date: | basilik99 on 2012-01-24 03:35:34 |
Changes
- icomment:
Hi, Indeed! I was about to open another ticket (probably a feature request) about the fact that given a class A which is an instance of class X (rather than oo::class as usual), then when copying A to B, the constructor of X does not get called. I think that would be the natural hook. I also had another concern: when I first used oo:::copy, I expected the new class to be created the same way as the first one. Eg: oo::class create CLASS1 \ { superclass MYBASE [oo::copy STORABLE [expr rand()]] ;# rand is because targetObject is not optional variable EXPRESSIONS puts "We are building a class." constructor {pL_EXPRESSIONS} \ { set EXPRESSIONS $pL_EXPRESSIONS } method WRITE {} \ { puts $EXPRESSIONS } export WRITE } oo::copy CLASS1 CLASS2 oo::define CLASS2 superclass MYBASE [oo::copy STORABLE [expr rand()]] 1) In that example, WRITE method on an object of CLASS1 works: the "variable" command given a class declaration makes that variable visible in all methods without having to write "my variable EXPRESSIONS" at the beginning of each method. That no longer works for CLASS2: the "variable" command does not seem copied... 2) Also, "rand" function does not get called once for CLASS1 and once for CLASS2. Its result is re-used when creating CLASS2. This forces me to override the superclasses of CLASS2 using oo::define command in order to generate a new copy of STORABLE class for CLASS2. Similarly, the text "We are building a class." gets printed only for CLASS1, not for CLASS2. In other words, it seems only the constructor, destructor and methods are copied. But it could be useful if all the code passed to "oo::class create" would be copied. Tell me if I should open another ticket with these. Thanks, Etienne - login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"