Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!tuegate.tue.nl!tuewsd!wsttss From: wsttss@lso.win.tue.nl (Steven van der Smagt) Newsgroups: comp.lang.eiffel Subject: Re: global objects Message-ID: <938@tuewsd.lso.win.tue.nl> Date: 22 Feb 90 09:25:07 GMT References: <925@tuewsd.lso.win.tue.nl> <3477@tukki.jyu.fi> Organization: Eindhoven University of Technology, The Netherlands Lines: 54 In article <3477@tukki.jyu.fi> sakkinen@jytko.jyu.fi (Markku Sakkinen) writes: > >>Can anyone help us out? Are such global object possible in >>Eiffel? >> ... > >The largest part of your problem can probably be solved by >"once functions" (OOSC 13.3). Some Eiffel expert please suggest >an elegant way to inhibit creating additional instances of >those classes. > Gary Wright proposed an 'elegant' solution to inherit from a class Global: >Create a class that contains only once functions (let's call the class GLOBAL). >Each function in GLOBAL returns a reference to a shared object. So >in GLOBAL you would have: features obj1 : CLASS1 is once Result.Create; end; obj2 : CLASS2 is once Result.Create; end; ... >For every class that needs access to these shared objects, inherit >from GLOBAL. If you anticipate almost every object needing access >to objects in GLOBAL, then put your feature definitions in HERE instead >of GLOBAL. By definition every class inherits from HERE so you don't >need to do anything special in you classes in order to obtain >access to the shared objects. Using the once mechanism to obtain shared objects, depends on the knowledge how Eiffel is implemented. Eiffel creates multiple instances of attributes, but only one (shared) instance of the methods. This confusion arises because of the 'natural' side effects of methods on the attributes of the object: you do not specify the attributes of an object as a parameter when you call a method. Isn't more logical to use the following syntax: method(object.attribute) instead of object.method Steven van der Smagt wsttss@lso.win.tue.nl Eelco Vriezekolk wsineel@lso.win.tue.nl