home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / object / 5054 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  3.6 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!howland.reston.ans.net!spool.mu.edu!agate!doc.ic.ac.uk!uknet!gdt!aber!fronta.aber.ac.uk!pcg
  2. From: pcg@aber.ac.uk (Piercarlo Grandi)
  3. Newsgroups: comp.object
  4. Subject: What is polymorphism _really_ ?
  5. Message-ID: <PCG.93Jan25220542@decb.aber.ac.uk>
  6. Date: 25 Jan 93 22:05:42 GMT
  7. References: <PCG.93Jan14154212@decb.aber.ac.uk> <1993Jan15.033713.27130@netcom.com>
  8.     <PCG.93Jan19231409@decb.aber.ac.uk> <1993Jan21.024452.6085@netcom.com>
  9. Sender: news@aber.ac.uk (USENET news service)
  10. Reply-To: pcg@aber.ac.uk (Piercarlo Grandi)
  11. Organization: Prifysgol Cymru, Aberystwyth
  12. Lines: 71
  13. In-Reply-To: objsys@netcom.com's message of 21 Jan 93 02: 44:52 GMT
  14. Nntp-Posting-Host: decb.aber.ac.uk
  15. X-Old-Subject: Re: FAQ  Part 1 (of 2) [ a bit of polemic ]
  16.  
  17.  
  18. >>> On 21 Jan 93 02:44:52 GMT, objsys@netcom.com (Bob Hathaway) said:
  19.  
  20. Hathaway> Anyway, how about a critique of my new polymorphism def?
  21.  
  22. Hathaway> What Is Polymorphism?
  23.  
  24. Hathaway> For a Brief Answer: Polymorphism is the ability of an object
  25. Hathaway> to assume or become many different forms of object and for
  26.  
  27. As far as I am aware this happens only in languages like Self and some
  28. frame based languages. I think I already commented on this, probably the
  29. article I wrote has not yet reached your site. Since I love repeating
  30. myself, for I have a strong fondness to repeat what I write, I will
  31. repeat here that my observation is that usually polymorphism is
  32. considered a property of procedures, and what you write should be
  33. rephrased as:
  34.  
  35.   Polymorphism occurs when a pointer is not restricted to point to
  36.   objects of a single class. A polymorphic procedure is one whose
  37.   parameters are (all or in part) specified as being of a polymorphic
  38.   pointer type/mode/class. When a pointer may point only to *related*
  39.   (e.g. by "inheritance") classes, the polymorphism is said to be
  40.   "inclusive"; when a pointer my point to any value, it is said to be
  41.   "parametric".
  42.  
  43.   "Ad hoc" polymorphism is a completely different concept, which
  44.   probably should not be called polymorphism at all, and occurs when the
  45.   name of a procedure can be overloaded, and can be used in several
  46.   different procedure definitions (with different signatures).
  47.  
  48. Neither polymorphism (inclusion or parametric) nor ad hoc polymorphism
  49. involve any ability for an object to assume different forms.
  50.  
  51. Polymorphism is about how restricted is the set of classes that a
  52. pointer value may denote (and pointer values are not, in virtually all
  53. languages, objects themselves), and ad hoc polymorphism is about
  54. procedure names and signatures, which are not objects either.
  55.  
  56. If you really think that in these three cases ...
  57.  
  58. 1)    int i; double d; char c; void *polymorph;
  59.     polymorph = &i;
  60.     polymorph = &d;
  61.     polymorph = &c;
  62.  
  63. 2)    void polymorphic(void *p,unsigned n) {
  64.       unsigned j;
  65.       for (j = 0; j < n; j++)
  66.         printf("0x%08x ",(unsigned *) ((char*) p  + 4*j));
  67.         }
  68.     polymorphic(stdin,4);
  69.     polymorphic("This is a char[] value, NUL terminated",4);
  70.     polymorphic(&polymorphic,4);
  71.  
  72. 3)    int ah_polymorphic(const char *const s)    { return atoi(s); }
  73.     int ah_polymorphic(const float f)    { return itrunc(f); }
  74.  
  75. (amusing note: the first two examples are in C, not even C++.)
  76.  
  77. ... there is any object that assumes different forms, you might try to
  78. indicate where it is.
  79.  
  80. Hathaway> P.S.  I should probably add you to the FAQ contributors list for your
  81. Hathaway>  "polemics", what do you think?
  82.  
  83. I'd rather not be associated with the FAQ, especially as it now mostly
  84. represents established wisdom... That's not something for me :-)
  85. --
  86. Piercarlo Grandi <pcg@aber.ac.uk> c/o Dept of CS
  87. University of Wales, Penglais, Aberystwyth SY23 3BZ, UK
  88.