Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!ucselx!ucsd!hub.ucsb.edu!eiffel!nosmo From: nosmo@eiffel.UUCP (Vince Kraemer) Newsgroups: comp.lang.eiffel Subject: Re: a problem in programming with Eiffel Summary: solution enlightenment association types Message-ID: <483@eiffel.UUCP> Date: 22 Jan 91 18:52:11 GMT References: <20022@hydra.gatech.EDU> Organization: Interactive Software Engineering, Santa Barbara CA Lines: 160 The solution is simple; depending upon the use of the language feature "association types". Association types appear as declarations in Eiffel code as ": like ". By redefining the anchor object in a class which takes advantage of this feature, all the associated objects are effectively redeclared. The library classes (specifically LINKED_LIST) were written with just such a problem in mind and allow the user to take advantage of this technique. By reviewing the code for linked_list, it is easy to determine that first and first_element are the anchors for the the routines in linked list which are originally declared as FIGURES. The sample code to illustrate the solution to this "problem" is appended to this message as a shar-chive file. (Note: this code has been tested using both the 2.2B and 2.3 releases. You will have to modify the .eiffel file to compile it under 2.2B, though) Vince Kraemer ISE Tech. Support (technical correspondence to: eiffel@eiffel.com) --------------------------------------------------------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by geneve!nosmo on Tue Jan 22 09:15:40 PST 1991 # Contents: .eiffel special_c_f.e special_f.e special_test.e echo x - .eiffel sed 's/^@//' > ".eiffel" <<'@//E*O*F .eiffel//' ------------ EIFFEL SYSTEM DESCRIPTION FILE ------------------- ROOT: special_test UNIVERSE: $EIFFEL/library/support $EIFFEL/library/structures $EIFFEL/library/graphics/figure $EIFFEL/library/graphics/window EXTERNAL: $EIFFEL/files/graphiclib.a -lX11 -lm PRECONDITIONS (y): ALL ---------------------------------------------------------------- @//E*O*F .eiffel// chmod u=rw,g=rw,o=r .eiffel echo x - special_c_f.e sed 's/^@//' > "special_c_f.e" <<'@//E*O*F special_c_f.e//' --|--------------------------------------------------------------- --| Copyright (C) Interactive Software Engineering, Inc. -- --| 270 Storke Road, Suite 7 Goleta, California 93117 -- --| (805) 685-1006 -- --| All rights reserved. Duplication or distribution prohibited -- --|--------------------------------------------------------------- --| Author: Vincent Kraemer @ Interactive Software Engineering --| Created: Tue Jan 22 07:59:21 1991 class SPECIAL_C_F export repeat complex_fig inherit COMPLEX_FIG redefine first, first_element feature first: SPECIAL_F is require not_empty: not empty do Result := first_element.item end; first_element: LINKABLE [special_f]; invariant end -- class SPECIAL_C_F @//E*O*F special_c_f.e// chmod u=rw,g=rw,o=r special_c_f.e echo x - special_f.e sed 's/^@//' > "special_f.e" <<'@//E*O*F special_f.e//' --|--------------------------------------------------------------- --| Copyright (C) Interactive Software Engineering, Inc. -- --| 270 Storke Road, Suite 7 Goleta, California 93117 -- --| (805) 685-1006 -- --| All rights reserved. Duplication or distribution prohibited -- --|--------------------------------------------------------------- --| Author: Vincent Kraemer @ Interactive Software Engineering --| Created: Tue Jan 22 08:04:34 1991 class SPECIAL_F export repeat FIGURE, special_call inherit FIGURE feature create is do closure.Create; end; special_call is do io.putstring ("Called special_call.\n"); end; recompute_closure is do end; convert_to_resolution (rv: REAL) is do end; origin: POINT; barycenter: POINT; duplicate: like Current is do end; translate (V: VECTOR) is do end; rotate (a: REAL; p: like origin) is do end; scale (f: REAL; a: like origin) is do end; display (w: graph_window) is do end; erase (w: GRAPH_WINDOW) is do end; contains (p: like origin): BOOLEAN is do end; invariant end -- class SPECIAL_F @//E*O*F special_f.e// chmod u=rw,g=rw,o=r special_f.e echo x - special_test.e sed 's/^@//' > "special_test.e" <<'@//E*O*F special_test.e//' --|--------------------------------------------------------------- --| Copyright (C) Interactive Software Engineering, Inc. -- --| 270 Storke Road, Suite 7 Goleta, California 93117 -- --| (805) 685-1006 -- --| All rights reserved. Duplication or distribution prohibited -- --|--------------------------------------------------------------- --| Author: Vincent Kraemer @ Interactive Software Engineering --| Created: Tue Jan 22 08:13:14 1991 class SPECIAL_TEST feature create is local sf: SPECIAL_F; scf: SPECIAL_C_F; do sf.create; scf.create; scf.put_right (sf); sf := scf.i_th (1); sf.special_call end; end -- class SPECIAL_TEST @//E*O*F special_test.e// chmod u=rw,g=rw,o=r special_test.e exit 0