home *** CD-ROM | disk | FTP | other *** search
- 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
- From: pcg@aber.ac.uk (Piercarlo Grandi)
- Newsgroups: comp.object
- Subject: What is polymorphism _really_ ?
- Message-ID: <PCG.93Jan25220542@decb.aber.ac.uk>
- Date: 25 Jan 93 22:05:42 GMT
- References: <PCG.93Jan14154212@decb.aber.ac.uk> <1993Jan15.033713.27130@netcom.com>
- <PCG.93Jan19231409@decb.aber.ac.uk> <1993Jan21.024452.6085@netcom.com>
- Sender: news@aber.ac.uk (USENET news service)
- Reply-To: pcg@aber.ac.uk (Piercarlo Grandi)
- Organization: Prifysgol Cymru, Aberystwyth
- Lines: 71
- In-Reply-To: objsys@netcom.com's message of 21 Jan 93 02: 44:52 GMT
- Nntp-Posting-Host: decb.aber.ac.uk
- X-Old-Subject: Re: FAQ Part 1 (of 2) [ a bit of polemic ]
-
-
- >>> On 21 Jan 93 02:44:52 GMT, objsys@netcom.com (Bob Hathaway) said:
-
- Hathaway> Anyway, how about a critique of my new polymorphism def?
-
- Hathaway> What Is Polymorphism?
-
- Hathaway> For a Brief Answer: Polymorphism is the ability of an object
- Hathaway> to assume or become many different forms of object and for
-
- As far as I am aware this happens only in languages like Self and some
- frame based languages. I think I already commented on this, probably the
- article I wrote has not yet reached your site. Since I love repeating
- myself, for I have a strong fondness to repeat what I write, I will
- repeat here that my observation is that usually polymorphism is
- considered a property of procedures, and what you write should be
- rephrased as:
-
- Polymorphism occurs when a pointer is not restricted to point to
- objects of a single class. A polymorphic procedure is one whose
- parameters are (all or in part) specified as being of a polymorphic
- pointer type/mode/class. When a pointer may point only to *related*
- (e.g. by "inheritance") classes, the polymorphism is said to be
- "inclusive"; when a pointer my point to any value, it is said to be
- "parametric".
-
- "Ad hoc" polymorphism is a completely different concept, which
- probably should not be called polymorphism at all, and occurs when the
- name of a procedure can be overloaded, and can be used in several
- different procedure definitions (with different signatures).
-
- Neither polymorphism (inclusion or parametric) nor ad hoc polymorphism
- involve any ability for an object to assume different forms.
-
- Polymorphism is about how restricted is the set of classes that a
- pointer value may denote (and pointer values are not, in virtually all
- languages, objects themselves), and ad hoc polymorphism is about
- procedure names and signatures, which are not objects either.
-
- If you really think that in these three cases ...
-
- 1) int i; double d; char c; void *polymorph;
- polymorph = &i;
- polymorph = &d;
- polymorph = &c;
-
- 2) void polymorphic(void *p,unsigned n) {
- unsigned j;
- for (j = 0; j < n; j++)
- printf("0x%08x ",(unsigned *) ((char*) p + 4*j));
- }
- polymorphic(stdin,4);
- polymorphic("This is a char[] value, NUL terminated",4);
- polymorphic(&polymorphic,4);
-
- 3) int ah_polymorphic(const char *const s) { return atoi(s); }
- int ah_polymorphic(const float f) { return itrunc(f); }
-
- (amusing note: the first two examples are in C, not even C++.)
-
- ... there is any object that assumes different forms, you might try to
- indicate where it is.
-
- Hathaway> P.S. I should probably add you to the FAQ contributors list for your
- Hathaway> "polemics", what do you think?
-
- I'd rather not be associated with the FAQ, especially as it now mostly
- represents established wisdom... That's not something for me :-)
- --
- Piercarlo Grandi <pcg@aber.ac.uk> c/o Dept of CS
- University of Wales, Penglais, Aberystwyth SY23 3BZ, UK
-