home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / object / 4681 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  2.8 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!mcsun!chsun!hslrswi!bytesmiths!steinman
  2. From: steinman@hslrswi.hasler.ascom.ch (Jan Steinman - Bytesmiths, 3946)
  3. Newsgroups: comp.object
  4. Subject: Re: Equality
  5. Message-ID: <1992Dec31.075228.9506@hasler.ascom.ch>
  6. Date: 31 Dec 92 07:52:28 GMT
  7. References: <1992Dec24.183708.2261@afs.com>
  8. Sender: news@hasler.ascom.ch
  9. Reply-To: steinman@hslrswi.hasler.ascom.ch
  10. Organization: Ascom Hasler AG
  11. Lines: 49
  12.  
  13. In article 2261@afs.com, greg@afs.com (Gregory H. Anderson) writes:
  14. >In article <1992Dec22.152021.4209@kei.is.s.u-tokyo.ac.jp>  
  15. >jeff@is.s.u-tokyo.ac.jp (Jeff McAffer) writes:
  16. >
  17. >> > May two objects of different classes be equal?
  18. >> 
  19. >> Yes
  20. >
  21. >Please explain how that could be.
  22.  
  23. Well, using a Smalltalk example: "1 = 1.0". "1" is a SmallInteger, and "1.0"
  24. is a Float. If you simply think of "=" as just another message send to some
  25. object, then it is up to the receiver of the message to determine if he/she/it
  26. is equal to the message argument. OOP systems that do not allow this are not
  27. polymorphic. (I don't want to start *that* discussion, but many people --
  28. Smalltalkers, mostly -- view polymorphism as essential to object orientation,
  29. while many others -- C++ers, mostly -- see polymorphism as unnecessary to OO.)
  30.  
  31. >Just because they happen to be exactly  
  32. >the same size, and happen to involve exactly the same instance variables,  
  33. >which happen to contain the same values, are two objects from different  
  34. >classes equal?
  35.  
  36. Absolutely not, unless they have defined that function as their equality
  37. message. About the only thing you can say for sure is that an object should
  38. be equal to itself.
  39.  
  40. >In Objective-C, this would be prima facie impossible,  
  41. >because the first instance variable is always 'isa', which points to the  
  42. >class. If two objects were equal in the sense I just defined, they would  
  43. >*have* to be members of the same class, or else their 'isa' pointer would  
  44. >be different. Maybe I'm missing something?
  45.  
  46. What I think you're missing is that "hybrid" OO systems provide you with
  47. built-in biases and notions about certain operations. Everyone with a C
  48. background has a preconceived notion of equality. Once you view "equals"
  49. as just another message, it becomes easier to imagine different uses for
  50. it. To take your example, you may decide that two objects should be
  51. considered "equal" if only a certain instance variable is equal, and that
  52. instance variable may be a computed hash or checksum of all the other instance
  53. valiables.
  54.  
  55. Another example might be that two objects are considered equal if a field
  56. representing the primary key in a database is equal.
  57.  
  58. ---
  59. : : Jan Steinman, Bytesmiths               steinman@hasler.ascom.ch : :
  60. : : 2002 Parkside Court, West Linn, OR 97068-2767 USA        +1 503 657 7703 : :
  61. : : Beundenfeldstrasse 35, CH-3013, Bern, Switzerland        +41 31 999 3946 : :
  62.