2

Sometimes I am inspecting or exploring my dowmain objects which contains many instance variables. I want to exclude all of them excepting the current specific ones of the instance I am exploring.

Say I am inspecting MyObject with instance variables: text, size, status.

  • dependents
  • owner
  • window
  • announcer
  • ...(lots of i.v.)
  • text
  • size
  • status

I want to view:

  • text
  • size
  • status

I have seen you can define the method inspectorClass, but is EyeInspector or EyeExplorer designed to configure this type of view? Should I subclass SelfEyeElement class?

4

2 に答える 2

0

Mooseのカスタマイズ可能なツールを使用したい場合があります。そこでは、ビューを非常に簡単に追加/変更できます。人道的評価のブログでは、例を見つけることができます

于 2014-07-16T14:28:59.490 に答える
0

私はちょうど試してみて、これを思いついた:

これがあなたのクラスだと想像してください:

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のインスタンスを調べると、 andMyClassのみが表示されますが、 は表示されません。firstVariablesecondVariablethirdVariable

MyClassInspector

とてもいい質問です!

更新: 通常、検査対象オブジェクトのスーパークラスではなく、検査対象オブジェクトのクラスで指定されたインスタンス変数のみを表示するインスペクターが必要な場合は、#addInstanceVariable:インスペクター クラスでこれを使用できます。

addInstancesVariable: elements
    self object class instVarNames do: [:name |
        elements add: (InstanceVariableEyeElement host: self object instVarName: name) ]
于 2014-07-02T17:20:07.730 に答える