I would suggest creating a class DifferenceFinderspecifically designed for the class whose instances you are trying to compare. For example, suppose you want to compare points. Then you will have a class PointDifferenceFinderwith three instance variables p, q, differenceand a protocol in lines
compare: aPoint with: anotherPoint
p := aPoint.
q := anotherPoint.
self compareClass ifFalse: [^self].
self compareX ifFalse: [^self].
self compareY ifFalse: [^self].
Where
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
Of course, the case Pointis simple, but this should give you an idea. Depending on your needs, you may just have a simple finder or one more complex one.
source
share