Newsgroups: comp.lang.eiffel Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!mstr!mstr!jcm From: jcm@mstr.hgc.edu (James McKim) Subject: Re: Three ways to use library-like classes Message-ID: <1991May6.140630.28179@mstr.hgc.edu> Keywords: library constants Sender: Usenet@mstr.hgc.edu (Action News Central) Nntp-Posting-Host: sc3.hgc.edu Reply-To: jcm@mstr.hgc.edu (James McKim) Organization: The Hartford Graduate Center, Hartford CT. References: <1991Apr30.140340.25415@bony1.bony.com> Date: Mon, 6 May 91 14:06:30 GMT In article <1991Apr30.140340.25415@bony1.bony.com> richieb@bony1.UUCP (Richard Bielak) writes: >I have seen two different ways of using classes that are >"library-like" (I mean classes like SINGLE_MATH, which only contain >various math routines, or classes that only define constants). I >thought of a third way to use these, that seems (to me anyway) a >little cleaner. Here are the three ways, I'll use SINGLE_MATH as an example: > >1) Inherit > > class COMPLEX is > inherit > SINGLE_MATH > feature > [...] > end; -- COMPLEX > > I don't like this method, since a COMPLEX number *is not* a > SINGLE_MATH library. Agreed. In addition, if we inherit from several of these, we risk we will almost certainly run into spurious name conflicts. > >2) Attribute > > class COMPLEX is > > feature > mlib : SINGLE_MATH; > [...] > end; -- COMPLEX > > Here any reference to a routine in SINGLE_MATH would be > "mlib.something". This is a little better than (1), however > "mlib" has to be Created before any calls will work. > > I don't like having to do the Create. Me either. Wastes a line of code, and at least a little space (the pointer to SINGLE_MATH). > >3) Expanded attribute (my way :-) > > class COMPLEX is > feature > mlib: expanded SINGLE_MATH; > [...] > end; -- COMPLEX > > Now I can can make calls "mlib.whatever" without having to do > a Create on "mlib". > > >It works. What do you think? > I like it! I have not used "expanded" before, but this _seems_ like a natural place! *------------------------------------------------------------------------------* Jim McKim (203)-548-2458 | _Give_ people fish and they eat for a day. Internet: jcm@mstr.hgc.edu | _Teach_ them to fish and they eat for a lifetime.