有时我正在检查或探索包含许多实例变量的域对象。我想排除所有这些,除了我正在探索的实例的当前特定实例。
假设我正在使用实例变量检查 MyObject:文本、大小、状态。
- 家属
- 所有者
- 窗户
- 播音员
- ...(很多 iv)
- 文本
- 尺寸
- 地位
我想查看:
- 文本
- 尺寸
- 地位
我看到你可以定义方法inspectorClass,但是EyeInspector 或EyeExplorer 是为了配置这种类型的视图而设计的吗?我应该继承 SelfEyeElement 类吗?
有时我正在检查或探索包含许多实例变量的域对象。我想排除所有这些,除了我正在探索的实例的当前特定实例。
假设我正在使用实例变量检查 MyObject:文本、大小、状态。
我想查看:
我看到你可以定义方法inspectorClass,但是EyeInspector 或EyeExplorer 是为了配置这种类型的视图而设计的吗?我应该继承 SelfEyeElement 类吗?
我刚刚尝试并想出了这个:
想象一下这是你的课:
Object subclass: #MyClass
instanceVariableNames: 'firstVariable secondVariable thirdVariable'
classVariableNames: ''
category: 'MyCategory'
然后制作以下检查员类:
EyeInspector subclass: #MyClassInspector
instanceVariableNames: ''
classVariableNames: ''
category: 'MyCategory'
将以下类方法添加到MyClass
:
inspectorClass
^ MyClassInspector
#addInstanceVariable:
并覆盖MyClassInspector
:
addInstancesVariable: elements
elements add: (InstanceVariableEyeElement host: self object instVarName: #firstVariable).
elements add: (InstanceVariableEyeElement host: self object instVarName: #secondVariable)
检查 and 的一个实例,MyClass
它只显示firstVariable
andsecondVariable
但不显示thirdVariable
:
非常好的问题!
更新:如果你想要一个检查器,它通常只显示在检查对象的类中指定的实例变量,而不是在检查对象的超类中,你可以#addInstanceVariable:
在检查器类中使用它:
addInstancesVariable: elements
self object class instVarNames do: [:name |
elements add: (InstanceVariableEyeElement host: self object instVarName: name) ]