From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,2c6139ce13be9980 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,3d3f20d31be1c33a X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,2c6139ce13be9980 X-Google-Attributes: gid1108a1,public X-Google-Thread: f43e6,2c6139ce13be9980 X-Google-Attributes: gidf43e6,public From: Nick Leaton Subject: Re: Interface/Implementation (was Re: Design by Contract) Date: 1997/09/09 Message-ID: <34151769.6343E724@calfp.co.uk>#1/1 X-Deja-AN: 270943223 References: <340C85CE.6F42@link.com> <3414BF1E.2E7C@ac3i.dseg.ti.com> Reply-To: nickle@pauillac X-NNTP-Posting-Host: calfp.demon.co.uk [158.152.70.168] Newsgroups: comp.object,comp.software-eng,comp.lang.ada,comp.lang.eiffel Date: 1997-09-09T00:00:00+00:00 List-Id: John G. Volan wrote: > Eiffel doesn't care about the order in which things are declared, but it > also lacks this notion of elaboration order. So how does it handle > intializing classwide globals? I seem to recall something about "once" > methods -- routines that get executed just once, the first time they are > called. The results are cached, and all subsequent calls just return > the cached results. Supposedly you can initialize classwide globals > inside such methods. Do I have that right? If so, it seems to me that > Ada's idiom for this is more straighforward than Eiffel's. (I'm not > saying it's better, just more straightforward for this particular > application.) One quick explaination first. x: MY_CLASS This does no allocation !!x or !OTHER_CLASS!x or !!x.make -- or some other feature declared as a creation feature The !! creates a object and allocates the memory. Prior to this, x is Void. The second case is interesting, OTHER_CLASS must conform to MY_CLASS. OK, back to global objects. x: MY_CLASS is once !!Result end The first time I use x, Result will be made. The second time I use x, the Result from the previous use will be returned. Think of it as a just in time singleton. So the order of creation is the order of use. Is this a problem where you want some objects initialised first? No, because you will want the objects initialised first in order to use them, but the use will create them. ie a DATABASE object. You can use this if it is a once feature anywhere, first use will create so you know it is created. If it needs something else to be create first, the client of DATABASE shouldn't be worried, DATABASE itself should create the appropiate objects, probably using a once feature. Are there any issues with once features? Yes, they never get 'deleted', once created they exist for the lifetime of the program. They could be large structures only used during the initialisation of the program, and therefore with never be garbage collected. However with a generational garbage collector, they will be compacted. (Once features a roots as far as GC is concerned) There is a solution to this problem if needed, just add a layer of indirection. -- Nick Eiffel - Possibly the best language in the world - unless proven otherwise.