4

我想使用重构浏览器以编程方式将实例变量添加到现有类:

| theClass className |
className := #MyClass.
theClass := (RBClass existingNamed: className)
                model: (RBNamespace new classNamed: className; yourself);
                yourself.
theClass addInstanceVariable: 'testIVar'

但是类没有被新的实例变量修改,我错过了什么?

4

1 回答 1

6

您忘记执行重构。尝试这个

| model className theClass iVarName |
className := #MyClass.
iVarName := 'testIVar'.
model := RBNamespace new classNamed: className; yourself.
theClass := (RBClass existingNamed: className)
                model: model;
                yourself.
(RBAddInstanceVariableRefactoring 
        model: model
        variable: iVarName
        class: theClass) execute.

您可能希望为新实例变量添加自动加入方法(getter 和 setter)

(RBCreateAccessorsForVariableRefactoring 
        model: model
        variable: iVarName
        class: theClass 
        classVariable: false) execute
于 2013-05-20T19:25:04.480 回答