Overview
| Artifact ID: | 54629160695311b4ca85e6267a8e76645e5498c7 |
|---|---|
| Ticket: | 3474460fffffffffffffffffffffffffffffffff
targetObject should be optional for oo::copy |
| User & Date: | basilik99 on 2012-01-26 06:42:28 |
Changes
- icomment:
Hi, Thanks for the correction about "variable" being copied. The rand trick comes from a higher need: I have a hierarchy of classes that I want to serialize to a file. Suppose the following classes (baseclasses to subclasses): A -> B -> C -> D -> E. A given object of type E will be serialized when its WRITE method will be called. Each class can write specific info. But all classes will write its class type to the serialization output file. I wanted to implement another class, STORABLE, which job would be to write these types to the file. With introspection, it is easy: look at the class name, go get a global constant of a name similar to it, output the value of that constant. So, I want the call to the WRITE method on an object of type E to give the following chain: E's WRITE -> STORABLE's WRITE -> D's WRITE -> STORABLE's write -> ... -> STORABLE's WRITE -> A's WRITE. 1) I first tried to insert STORABLE as a mixin in the hierarchy, but STORABLE was accepted only once for the whole hierarchy (in the top superclass) and hence STORABLE's WRITE was called only once, not 5 times. Also, STORABLE's WRITE was called BEFORE the implementation of the class it is applied to: I could work with this, but it is not was I expected (however, I was new to mixins...). 2) The I tried using STORABLE as a superclass. Again, all superclass commands were ignored except the one in the topmost class. To TclOO to see its the same class, I made a copy of STORABLE each time I used it as superclass. And that's what explains the oo::copy. The rand is only because I wanted a different name for each STORABLE class copies. There may be better ways to achieve my goal. Suggestions are welcome. Thanks, Étienne
- login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"