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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: 1108a1,2c6139ce13be9980 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,3d3f20d31be1c33a X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,2c6139ce13be9980 X-Google-Attributes: gidf43e6,public From: paul.johnson@gecm.com (Paul Johnson) Subject: Re: Interface/Implementation (was Re: Design by Contract) Date: 1997/09/09 Message-ID: <5v33lg$l7u$2@miranda.gmrc.gecm.com>#1/1 X-Deja-AN: 270934419 References: <340C85CE.6F42@link.com> <3414BF1E.2E7C@ac3i.dseg.ti.com> Organization: GEC-Marconi Research Centre Newsgroups: comp.object,comp.software-eng,comp.lang.ada,comp.lang.eiffel Date: 1997-09-09T00:00:00+00:00 List-Id: In article <3414BF1E.2E7C@ac3i.dseg.ti.com>, johnv@ac3i.dseg.ti.com says... >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? Yes. For example, in a discrete event simulation system I would want to have a global event queue. The class holding it would look something like this: class THE_QUEUE feature the_queue: PRIORITY_QUEUE [EVENT] is -- The global event queue. once !!Result; -- Create the result of this function end; end; This class can then be inherited by any other class which needs to access the event queue. Within such a class I can use code such as the_queue.item.trigger; the_queue.remove; the_queue.put (new_event); Every descendant of THE_QUEUE gets the same global queue object. >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.) In Ada you have to worry about the order of initialisation to accomodate any dependencies. In Eiffel you just use the once routines. Any interdependencies between once functions will be reflected in their own call graphs, and get taken care of automatically. The Eiffel mechanism can even take care of circular dependencies, although it does need a little care. Suppose that after creating the result object, "the_queue" called some other function (maybe a "once" function) which referred to "the_queue". At this time "the_queue" will return its current value of "Result" without executing again. You can't execute a "once" function twice, even by recursion. In Ada, as I understand things, you would have to split the various bits of initalisation into non-recursive bits, and hence make the process visible at a higher level than would otherwise be necessary. Paul. -- Paul Johnson | GEC-Marconi Ltd is not responsible for my opinions. | +44 1245 242244 +-----------+-----------------------------------------+ Work: | You are lost in a twisty maze of little Home: | standards, all different.