Re: static polymorphism --- How it actually Happens ?
On Jun 4, 12:16 pm, ld <Laurent.Den...@gmail.com> wrote:
On 4 juin, 10:35, James Kanze <james.ka...@gmail.com> wrote:
On Jun 3, 5:39 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
Pallav singh wrote:
Can anyone explain How it actually Happens ?
polymorphic behaviour needed is invariant and can be
determined at compile time. Then the Curiously Recurring
Template Pattern (CRTP) can be used to achieve static
polymorphism, which is an imitation of polymorphism in
programming code but which is resolved at compile time and
thus does away with run-time virtual-table lookups.
Static polymorphism isn't an imitation of anything. In
canonical OO-speak, "polymorphism" is the ability of different
objects to respond to the same message in different ways.
Polymorphism isn't restricted to OO; it's a well established
concept, first described, I think, in a paper by Christopher
Strachey in 1967. The "reference", as far as I know, is "On
Understanding Types, Data Abstraction, and Polymorphism", by
Cardelli and Wegner
(http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf). The
concept includes such things as function overloading and
implicit conversions, as well as parametric polymorphism
except that in this paper, parametric polymorphism doesn't
refer to C++ templates (i.e. type injection) but to Java
generics (i.e. type erasure) which are fundamentally
different.
The paper refers to neither C++ templates nor Java generics,
since neither existed at the time it was written. The paper
also isn't really concerned with implementation details; both
C++ templates and Java generics meet its definition of
parametric polymorphism. (The authors do cite Ada's generic
procedures as an example parametric polymorphism. As far as I
know, Ada's generic procedures are implemented very much like
C++'s templates.)
A refinement/extension is needed to be clear/complete.
The paper is from 1985. Obviously (or hopefully), there's been
some evolution since then; if nothing else, both parametric
polymorphism and inclusion have become very mainstream. I don't
think that the basic theoretical aspects have changed much,
however.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34