eiffel examples n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Eiffel examples PowerPoint Presentation
Download Presentation
Eiffel examples

Loading in 2 Seconds...

play fullscreen
1 / 5
callum-kramer

Eiffel examples - PowerPoint PPT Presentation

76 Views
Download Presentation
Eiffel examples
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  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:INTEGERis -- routine with returned value do Result :=count +1 -- returned value end feature -- the public class data count :INTEGER increase(c :INTEGER ) :INTEGERis -- 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.