2013-05-20 5 views
4
내가 리팩토링 브라우저를 사용하여 기존 클래스에 프로그래밍 방식으로 인스턴스 변수를 추가 할

:Refactoring Browser를 사용하여 인스턴스 변수를 추가하는 방법은 무엇입니까?

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

하지만 클래스는 내가 무엇을 놓치고, 새로운 인스턴스 변수로 수정되지 않는 이유는 무엇입니까?

답변

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. 

당신이 변수 새 예를 들어 authomatic 가입 방법 (getter 및 setter)를 추가 할 수 있습니다 시도

(RBCreateAccessorsForVariableRefactoring 
     model: model 
     variable: iVarName 
     class: theClass 
     classVariable: false) execute