Download presentation
Presentation is loading. Please wait.
1
Eiffel examples
2
Example 1 class C creation default_create feature {ANY} -- the public class data count: INTEGER element: DOUBLE end; features - the data an object may store and operations that may be performed on an object. feature {ANY} = feature feature {NONE} = feature {} default_create – default creation function
3
Example 2 class C creation feature {NONE} -- the private class data add: INTEGER is -- routine with returned value do Result := count + 1 -- returned value end feature -- the public class data count : INTEGER increase(c : INTEGER ) : INTEGER is -- argument and returned value do count := c Result := add -- returned value end end; The {NONE} appearing after the feature reserved word states that all of the following features are available to objects who are of type NONE.
4
Example 2 (cont) class MAIN creation make feature {NONE} -- the private class data make is local c : C do !!c -- c creation (= create c) print(c.increase(2).out + “,”) print(c.count.out) end end; Output – 3,2
5
Example 3 class C creation -- Constructors definitions make, make_init feature count: INTEGER make is -- Constructor without argument do count := 0 end make_init (c : INTEGER ) is -- Constructor with argument do count := c end end; Constructor don't need to have the same name as the class. Class can have multiple constructors with different names.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.