home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ulowell!m2c!bu.edu!inmet!spock!stt
- From: stt@spock.camb.inmet.com (Tucker Taft)
- Newsgroups: comp.object
- Subject: The definition of polymorphism
- Message-ID: <1993Jan26.223826.29345@inmet.camb.inmet.com>
- Date: 26 Jan 93 22:38:26 GMT
- Sender: news@inmet.camb.inmet.com
- Distribution: comp.object
- Organization: Intermetrics Inc, Cambridge MA
- Lines: 66
- Nntp-Posting-Host: spock
-
-
- In debating the meaning of polymorphism, it
- seems important to distinguish between where a
- *program* is polymorphic in some way, and where some *run-time*
- entity (like an object) is polymophic.
-
- In many object-oriented systems, no object can change its
- underlying type/class at run time. However, if you
- look at a program that manipulates objects, you find
- that a given name is used to reference (over different
- executions of the same piece of program text) objects
- of different underlying types/classes.
-
- For a "conventional" strongly typed language like Ada 83, this kind
- of "polymorphism" doesn't happen, except inside some kind of
- explicit "template" or "generic." This is compile-time parametric
- polymorphism.
-
- When you go from a conventional strongly typed language
- to an object-oriented strongly typed language (such as Ada 9X
- or Eiffel), you now find a single name within a given
- piece of program text refers to objects of different types/classes
- on different executions.
-
- However, because it is "strongly typed," we
- do know *something* about the set of types for the objects
- that a given name might reference. This might be called the
- "compile-time" type for the *name* (not the object), or the
- "formal class" (or the "reference type" or ... -- standardization
- of terminology would help someday ;-).
-
- This "formal class" determines which operations
- are permitted (at compile-time) on the *name*, and generally
- (at least in most simple type systems!) represents a lower bound on the
- set of operations defined for any *object* that might be referenced
- by the name at run-time. This is run-time/dynamic (inclusion)
- polymorphism. (There is also run-time parametric polymorphism, though
- not as frequently in compiled languages.)
-
- Now, back to a tentative definition of polymorphism:
-
- Polymorphism is where a given occurrence of a name within a given
- piece of program text can refer to objects of different
- types at run-time. This polymorphism could be either
- compile-time or run-time, and either parametric or inclusion.
-
- If the polymorphism is strongly typed, then the occurrence of the
- name has various compile-time attributes that represent a lower
- bound on the properties of any possible object that will be referenced
- at run-time.
-
- (Note that the compile-time polymorphism inherent
- in C++ templates is not strongly typed (until instantiation time),
- whereas the run-time polymorphism inherent in C++ class pointers
- and references is strongly typed. In Eiffel and Ada 9X, both the
- compile-time and run-time polymorphism is strongly typed.)
-
- (In addition to the above, there is "ad hoc" polymorphism
- otherwise known as overloading, where two different occurrences of
- the same name nevertheless resolve to be references
- to different entities at *compile-time*, but that's not
- usually of great interest when people discuss polymorphism.)
-
- S. Tucker Taft stt@inmet.com
- Intermetrics, Inc.
- Cambridge, MA 02138
-