gpt4 book ai didi

refactoring - 如何使用重构浏览器添加实例变量?

转载 作者:行者123 更新时间:2023-12-05 00:29:57 26 4
gpt4 key购买 nike

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

| theClass className |
className := #MyClass.
theClass := (RBClass existingNamed: className)
model: (RBNamespace new classNamed: className; yourself);
yourself.
theClass addInstanceVariable: 'testIVar'
但是该类没有使用新的实例变量进行修改,我缺少什么?

最佳答案

你忘了执行你的重构。尝试这个

| 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

关于refactoring - 如何使用重构浏览器添加实例变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16656426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com