=== Top of the Swiki === Attachments ===

FAQ: Copying a class

Question:
How do I copy a class if subclassing is not feasible?


Answer:

First possibility:

Use ClassDescription>>copyAllCategoriesFrom:.

Specifically, define a class (MyNewClass) and evaluate the following in a workspace:

MyNewClass copyAllCategoriesFrom: Old.
MyNewClass copyAllCategoriesFrom: Old class.


John Tobler: When I tried this, all class methods were copied into instance methods and no Class methods were copied. I belive the correct incantations are these:
MyNewClass copyAllCategoriesFrom: Old.
(MyNewClass class) copyAllCategoriesFrom: Old class.

Second possibility:
  1. fileout the original class,
  2. rename the original class in the image to the new name
  3. file the original class back in (thus recreating the old class in the image).
  4. There may still be a few references to the old class in the renamed class, but the references are easily found and changed.