Version 2 of Semantics of the oo::class command

Updated 2009-11-09 02:04:15 by mpdanielson

The "oo::class create <name>" command will fail if the class <name> already exists. This is in contrast to the behaviour of the "proc" command, which overwrites an existing proc. The behavior of "oo::class" makes it awkward to use "package forget; package require" to refresh the contents of a package that defines a class. A package definition like:

namespace boo {
  oo::class create Boo {
    method boo {} { puts "ouch" }
  }
}

causes the following problem:

> package require boo

1.0

> package forget boo

> package require boo

can't create object "Boo": command already exists with that name

This can be avoided by splitting the definition of the class as in:

namespace boo {
  catch {oo::class create Boo}
  oo::define Boo {
    method boo {} { puts "ouch" }
  }
}

but it seems awkward to have to do this for every class that might be used in a package. What is the reasoning behind making it an error to re-"create" a class?