Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!agate!helios.ee.lbl.gov!ucsd!hub!eiffel!bertrand From: bertrand@eiffel.UUCP (Bertrand Meyer) Newsgroups: comp.lang.eiffel Subject: Re: redefining constant features Summary: Constants don't change Message-ID: <183@eiffel.UUCP> Date: 16 Jul 89 19:49:26 GMT References: <976@clyde.Concordia.CA> Organization: Interactive Software Engineering, Santa Barbara CA Lines: 34 From <976@clyde.Concordia.CA> by marcap@concour.CS.Concordia.CA (Marc Pawlowsky): > Why is it not legal to redefine a constant feature? > [The following produces a compilation error]: > > class IMAGE ... feature > nb_directions: INTEGER is 4; ... > > class HEX_IMAGE ... inherit > IMAGE redefine nb_directions .... > feature > nb_directions: INTEGER is 6; ... A constant attribute is what the name indicates: its value does not change, either in the class or in any descendant. Actually the same message contains the solution: > Yet if I change the code [as follows] the program compiles: > > in IMAGE: nb_directions: INTEGER is do Result := 4 end; > in HEX_IMAGE: nb_directions: INTEGER is do Result := 6 end; This is the appropriate way to go: in such a case, use a function. My only pet complaint is that constant attributes should be used in each class rather than the manifest constants 4 and 6. -- Bertrand Meyer bertrand@eiffel.com