"Conceptually the same as" in Smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

"Conceptually the same as" in Smalltalk

Sean P. DeNigris
Administrator
I've read that #= can ignore non-domain things like cache data, but what about domain-related things that do not effect identity?

Let's say I have a Person class. Obviously, the #name would be compared in #=. But what if there was a collection of #phoneNumbers, and aPerson and anotherPerson differed only in that one of them had been updated with an extra #phoneNumber? Should #= answer true or false? I'm guessing true since e.g. in a unique collection there should only be one of that particular person. Then there would have to be another message like #exactlyTheSameAs:. Is there a well-known pattern distinguishing "Conceptually the same as" from "exactly the same as, but not #=="?

Thanks.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: "Conceptually the same as" in Smalltalk

abergel
Hi Sean,

This is a complex question. Essentially, this is the difference between a plain normal class and an abstract data type.
Abstract data type will typically override hash and = to give the ability to structurally compare them.
From my rather long experience in programming, I do not remember to have overriding = and hash, even once. This is error prone and not justified. Also, if you have two different objects that are equals, then it often leads to complex situation to debug (Have you ever used “Transcript show: my object hash asString”?).

In your case of Person, I guess each person has to have a unique Id (social number?). This is how I would solve this.

Cheers,
Alexandre


On Oct 2, 2014, at 4:41 PM, Sean P. DeNigris <[hidden email]> wrote:

> I've read that #= can ignore non-domain things like cache data, but what
> about domain-related things that do not effect identity?
>
> Let's say I have a Person class. Obviously, the #name would be compared in
> #=. But what if there was a collection of #phoneNumbers, and aPerson and
> anotherPerson differed only in that one of them had been updated with an
> extra #phoneNumber? Should #= answer true or false? I'm guessing true since
> e.g. in a unique collection there should only be one of that particular
> person. Then there would have to be another message like #exactlyTheSameAs:.
> Is there a well-known pattern distinguishing "Conceptually the same as" from
> "exactly the same as, but not #=="?
>
> Thanks.
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Conceptually-the-same-as-in-Smalltalk-tp4782118.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.