Pharo:如何比较不同检查员的对象?

Jua*_*njo 5 reflection smalltalk pharo inspector

我正在使用Pharo 4.假设我的对象已经实现了很好的相等和哈希方法.

如何直观地比较不同检查员中的两个或N个物体?在视觉上我的意思是并排比较,我可以很容易地看出差异.

我尝试了所有实例,但一段时间后变得乏味.

Lea*_*lia 0

我建议DifferenceFinder为您要比较其实例的类创建一个量身定制的类。例如,假设您想要比较点。然后你会得到一个PointDifferenceFinder带有三个实例变量p, q, difference和一个协议的类

compare: aPoint with: anotherPoint
  p := aPoint.
  q := anotherPoint.
  self compareClass ifFalse: [^self].
  self compareX ifFalse: [^self].
  self compareY ifFalse: [^self].
Run Code Online (Sandbox Code Playgroud)

在哪里

compareClass
  ^p class == q class
    ifFalse: [difference := 'not of the same class'];
    yourself

compareX
  ^p x = q x
    ifFalse: [difference := 'not with the same x'];
    yourself

compareY
  ^p y = q y
    ifFalse: [difference := 'not with the same y'];
    yourself
Run Code Online (Sandbox Code Playgroud)

当然,这个例子Point很简单,但这应该给你一些想法。根据您的需要,您可以只使用一个简单的取景器,也可以使用一个更复杂的取景器。