Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!odi!dlw From: dlw@odi.com (Dan Weinreb) Newsgroups: comp.lang.c++ Subject: Re: Class scope and virtual functions Message-ID: <1989Nov12.221446.23494@odi.com> Date: 12 Nov 89 22:14:46 GMT References: <21847@gryphon.COM> <10935@csli.Stanford.EDU> <1989Nov7.073836.23166@brutus.cs.uiuc.edu <20130@brunix.UUCP> <1989Nov11.033053.4148@sjsumcs.sjsu.edu> Reply-To: dlw@odi.com Distribution: na Organization: Object Design, Inc. Lines: 47 In-Reply-To: horstman@sjsumcs.sjsu.edu's message of 11 Nov 89 03:30:53 GMT In article <1989Nov11.033053.4148@sjsumcs.sjsu.edu> horstman@sjsumcs.sjsu.edu (Cay Horstmann) writes: Several people asked for the possibility of calling super->f() to invoke the method f() in the immediate superclass. I don't see why that would be such a wonderful feature. YOU built the inheritance tree, so you know the name of the superclass and can invoke it with Becuase sometimes you do NOT build the inheritance tree! Suppose George writes a class called borders_mixin. Nobody is ever intended to instantiate this class. George installs it in a library of reusable component classes. He advertises that if you are making your own window class, and you'd like your window to have borders, all you need to do is inherit from borders_mixin, and, voila, nice borders. Now Martha wants to make a particular window class. She looks through all the libraries, and discovers some nice goodies, including George's borders_mixin, as well as Fred's label_mixin and Laura's pulldown_bar_mixin. She makes her new class inherit from all three of those, in no particular order, since they're really orthogonal features. So Martha determined the order, not George. Now, each "mixin" class might want to handle the "redraw yourself" virtual function, by redrawing its own contribution, and then passing on control to the next class down the line. This is what the CLOS "call-next-method" function is for, and this is what "super->f()" is essentially for (except that "super" is a somewhat poor name in the presence of multiple inheritance). There are scenarios involving only single inheritance that answer your question (as earlier postings pointed out), but I think the multiple inheritance scenario makes a more powerful case for the benefits of method combination. These concepts are explained at greater length and with greater clarity in an excellent book: "Object-Oriented Programming in Common Lisp" by Sonya Keene. Even if you're a C++ programmer and are only somewhat familiar with Lisp, you shouldn't have much trouble following the book's explanation of what multiple inheritance is good for, and how to use it in the manner in which I describe above. Dan Weinreb Object Design, Inc. dlw@odi.com