Path: utzoo!attcan!uunet!mcvax!ukc!etive!lfcs!db From: db@lfcs.ed.ac.uk (Dave Berry) Newsgroups: comp.lang.c++ Subject: Re: Container classes (was Re: friend) Message-ID: <816@etive.ed.ac.uk> Date: 5 Oct 88 16:51:26 GMT References: <61@cybaswan.UUCP> <1988Sep2.174327.6439@ateng.uucp> <78@cybaswan.UUCP> <1988Sep15.151514.20657@ateng.uucp> <763@esl.UUCP> <1988Sep27.103559.4881@ateng.ateng.com> Sender: news@etive.ed.ac.uk Reply-To: db@lfcs.ed.ac.uk (Dave Berry) Organization: Laboratory for Foundations of Computer Science, Edinburgh Uni Lines: 32 In article <1988Sep27.103559.4881@ateng.ateng.com> chip@ateng.ateng.com (Chip Salzenberg) writes: > >The whole issue of container classes is one that gets religious pretty >quickly. Smalltalk devotees -- and their acolytes, the Objective C folks -- >rant on about container classes that work the same no matter what they >contain. Personally, I consider the whole issue a red herring. > >For example, the Objective C book gives the example of iterating across all >objects in a collection, adding up their weights. The hidden gotcha: What >guarantee is there that all objects in the collection respond correctly, or >at all, to the "getWeight" message? The likely answer: "Well, I know >because I put them there." In that case, you don't *really* have a >heterogenous collection. >-- >Chip Salzenberg or That's where parameterised types are useful. You can create collection objects that are parametised on the type they contain. Then an iteration function on that type can be used with the collection. The combination of type parameters and subtyping mens you can define collections in library classes which can be used with a range of types, provided those types form a type hierarchy. If you want, you can use collections of just one type, as in your hashnode example. The same library class can be used for homogeneous collections or for heterogeneous collections. I don't know how Bjarne is designing the C++ parametised types, but I assume that they'll work along these lines. Dave Berry. db@lfcs.ed.ac.uk