Search code examples
tclitcl

Any substitute for itcl::find in native OO?


Is there any substitute for itc::find in native OO.

I need to delete all classes in a particular namespace My code runs like:

foreach class [::itcl::find classes ::MYNAMESPACE::*] {catch {::itcl::delete class $class}}

How do I do this in native OO?


Solution

  • The simplest way of doing this is to make all your classes subclass a dummy class that doesn't need to do anything, say MYNAMESPACE::DeletionToken. Then, just delete that dummy class with MYNAMESPACE::DeletionToken destroy; all the subclasses and instances will then be automatically slaughtered neatly. This also works with mixins and metaclasses. Also remember that TclOO supports multiple inheritance so none of this needs to disturb your existing code much.