Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!gatech!udel!rochester!PT!g.gp.cs.cmu.edu!dld From: dld@g.gp.cs.cmu.edu (David Detlefs) Newsgroups: comp.lang.c++ Subject: C++ libraries... Message-ID: <1096@g.gp.cs.cmu.edu> Date: Mon, 28-Sep-87 18:07:00 EDT Article-I.D.: g.1096 Posted: Mon Sep 28 18:07:00 1987 Date-Received: Tue, 29-Sep-87 07:28:00 EDT Organization: Carnegie-Mellon University, CS/RI Lines: 52 In a recent article, Mike Mowbray proposed a discussion of how the advent of multiple inheritance might change the design of class libraries. I would like to extend this discussion to include the introduction of parameterized types into C++. Certainly many things are best done using inheritance, but it's always seemed to me that proponents of inheritance sometimes attempt to apply it where simpler methods (no pun intended) would suffice. Mowbray's hash table example seems to me to be an example of this. Hash_table seems like a perfect parameterized class to me. His inheritance implementation, whether single or multiple, seemed much more complicated than this (Dr.? Mowbray (May I call you Mike?): what would the signature of a "lookup" operation for your proposed hash table be? Would one have to create a dummy "Hashed" object with the appropriate key data, and call lookup with that? Anyway, my point here is that inheritance need not be the only way of creating new types in the language. I would claim that many (if not most) of the kinds of classes one would want to provide in a class library are best done as parameterized types, both from a efficiency and conceptual simplicity standpoint. This is especially true of "container" classes. One should not add features to a language without good reason, but my own feeling is that the inheritance model gets bent out of shape when it is applied to things it doesn't handle well, and that this is sufficient reason for adding complementary features that handle those cases well. I have seen a draft of a paper by Dr. Stroustrup describing a design for the addition of parameterized types to C++. It seemed to me quite reasonable. Unlike multiple inheritance, however, there are no rumors of the imminent addition of this feature to the language. Some issues that I don't remeber if that paper addressed: What can a class be parameterized over? My experience with CLU made me appreciate the utility of parameterized classes; however, CLU did not allow one to parameterize a class over a function type. This means one could not write "Hash_table" as I did above. This should be allowed. How do inheritance and parameterized classes interact? I think that if a class is not originally parameterized, you probably should not be able to introduce parameters for subclasses. I'm not sure though, maybe this might be useful. Does anyone have any examples? Can one derive a class directly from a parameterized class, getting a parameterized subclass? Intution tells me this might be useful, though I've not thought about it a lot. Hoping to stimulate some discussion... Dave Detlefs