Path: utzoo!attcan!uunet!mcvax!ukc!its63b!db From: db@its63b.ed.ac.uk (D Berry) Newsgroups: comp.lang.c++ Subject: Re: oo definition request Message-ID: <1399@its63b.ed.ac.uk> Date: 31 May 88 19:30:36 GMT References: <77300011@uiucdcsp> Reply-To: db@itspna.ed.ac.uk (Dave Berry) Organization: University of Edinburgh Lines: 69 In article <77300011@uiucdcsp> johnson@uiucdcsp.cs.uiuc.edu writes: > >A polymorphic procedure is one that takes arguments of many different >types. There are several different kinds of polymorphism. ML features >"parametric" polymorphism. (I hope I get all these names right.) C++ >features "inclusive" polymorphism, where an instance of a subclass can >be treated as if it were in a superclass. A type system for Smalltalk >would have to treat "ad-hoc" polymorphism, which is where unrelated >objects can all implement the same operation, but in entirely different >ways. C++ also allows ad-hoc polymorphism (a.k.a. overloading), by allowing redefinition of members in subclasses. Most object-oriented languages do this. It's easy to confuse inclusive polymorphism with subtyping. A function is polymorphic if it operates on a variety of types. When members are redefined then we also have overloading, even if functions are only redefined in subclasses (subtypes) of a given class. Another way of looking at this is to say that when a member is redefined, it only inherits the type of the corresponding member in the superclass, not the definition. Note 1: I'm disagreeing with Cardelli & Wegner here. They (to my mind) confuse inheritance and subtyping. Note 2: C++ also has pure overloading, though that's not relevant here. >Languages like Trellis/Owl show that ad-hoc polymorphism can be >translated into inclusive polymorphism with multiple inheritance. >If a procedure needs to be able to operate on objects in class A or >class B then you can just define a common superclass to describe >their commonality. You can describe the fact that they each have a member of a certain name, but the actual functions are still different. Thus you still have ad-hoc polymorphism (as above). The languages I've seen with multiple inheritance require each class to specify their superclasses. This means that if overloading (ad-hoc polymorphism) is "replaced by multiple inheritance", every case of overloading must be anticipated by the program or library developer. Does Trellis/Owl have this restriction? Or does it allow a programmer to specify existing classes as subclasses of a new class? Presumably this would require either: 1. a dynamic programming environment to modify the original classes or 2. fairly tight restrictions on such a scheme, such as requiring every specified subclass to override every public member of the new superclass, so that the new superclass would essentially exist only for type-checking. >The question, "Which is more important in an object-oriented >programming language, inheritance or message-passing?" is the same as >saying "Which kind of polymorphism is most important, inclusive or ad-hoc"? > >For further information, see the paper by Cardelli and Wegner in >Computing Surveys a few years ago. 1985, pp.471-522. On p.477 the authors write: "... ad-hoc polymorphism is some kind of _apparent_ polymorphism whose polymorphic character disappears at close range." This is why I prefer the term "overloading" to "ad-hoc polymorphism", since it stresses the distinction between a polymorphic function and a group of functions with the same name (and possibly the same type). -- ------------------------------------------------------------------------------- Dave Berry. db%lfcs.ed.ac.uk@nss.cs.ucl.ac.uk Free jazz, not markets