tcl

Borrow another class methods in TclOO


In TclOO if I want to borrow only particular method from the other class I just copy it with info class definition class method. But maybe there is more elegant way to do that? Thank you in advance.


Solution

  • To copy a definition, you basically do exactly that. (I explicitly designed info class definition to make that easy, even in tricky cases.) It only works for methods implemented using method, not other types (such as ones writen directly in C).

    But you have other options that might suit. Notably:

    They're not suitable for all cases. In particular, classes designed to be used as dynamic mixins probably should be careful with how they bootstrap any state they depend on, and when forwarding you are forwarding to a different entity that may have it's own separate state.