home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6178 < prev    next >
Encoding:
Text File  |  1992-09-15  |  2.4 KB  |  49 lines

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