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