home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.programmer
- Path: sparky!uunet!psinntp!afs!greg
- From: greg@afs.com (Gregory H. Anderson)
- Subject: Re: Multiple init: functions defined
- Message-ID: <1992Sep15.032540.1762@afs.com>
- Sender: greg@afs.com
- Reply-To: greg@afs.com
- References: <60157@mimsy.umd.edu>
- Date: Tue, 15 Sep 1992 03:25:40 GMT
- Lines: 37
-
- In article <60157@mimsy.umd.edu> alex@cs.umd.edu (Alex Blakemore) writes:
- > actually having several functions share a single name can be very
- > useful. Its called overloading of course and exists in languages like
- > Ada and C++. As long as the compiler can resolve the reference to the
- > correct call, and you only overload semantically similar operations, it
- > can be a great convenience.
- >
- > There's no need to remember half a dozen names for the same conceptual
- > operation. you could then use just setValue: instead of setStringValue:,
- > setIntValue:, setFloatValue: etc - the compiler can figure out which one
- > you meant from the argument type and you can worry about other things.
- > Its convenient for some of the same reasons that polymorphism is.
-
- Well, sorta. If you think about it, though, operator overloading in C++ is
- the same as reusing method names in multiple Obj-C classes, which is
- valid. For example, the overloaded C++ method (a+b) really means, "using
- the plus operator, as 'a' class defines it, apply object b to object a".
- In Obj-C, we would simply say [a add:b]. AS LONG AS 'A' AND 'B' ARE BOTH
- OBJECTS, NOT SIMPLE DATA TYPES, you can do anything you want to them
- inside the add: method in any class. Cells, for example, can be queried
- for their values in several ways, and some of AFS's private classes define
- a few more storage types. (For example, a date class might return a
- properly formatted string in response to [date stringValue], but a Julian
- number in response to [date intValue]. But you have to pass around the
- OBJECTS to do this.
-
- What we have here is a syntactical different between two languages--one
- lets you use the old familiar operators, like + and ==; the other makes
- you use named messages--but the result is the same: overloading. Another
- case where the C++ bigots are spreading misinformation about our beloved
- language. 8^)
-
- --
- Gregory H. Anderson | "We're very tolerant around here,
- Benevolent Dictator-for-Life | being only amateurs ourselves."
- Anderson Financial Systems | - Tortoise (Godel, Escher, Bach)
- greg@afs.com (Nextmail OK) |
-