Download presentation
Presentation is loading. Please wait.
Published byKerrie Dortha Morton Modified over 9 years ago
1
Eiffel Programming Language
2
Chad Frommeyer CSC 407/507 Fall 2005 Dr. Richard Fox
3
History 1985 Language Development Began Developed by Bertrand Meyer of Interactive Software Engineering 1986 First Compiler Delivered 1987 Commercial Applications Developed 1991 NICE Founded (Non-Profit International Consortium for Eiffel) NICE controls evolution, standardization and basic class definitions for Eiffel 1996 Commercial Eiffel based development system becomes available (iss-base). Decendent of Algol and ADA
4
Overview Pure object oriented language Strong statically typed Automatic memory management/Garbage collection Supports ADTs Supports Generic Classes Supports By Value and By reference semantics Promotes simplicity (Readable, not Writeable) Non-Object Oriented Capabilities/Low Level Functionality (C-Lang) Some Compilers only generate C source code Design By Contract (Reliability) Exception Handling Supports separate library compilation Supports In-Class Documentation Root class starts execution
5
Overview (Continued) Statement delimiter (;) allowed, not required, typically used in muti- statement line Is not case sensitive Doesn’t support global variables Doesn’t support union types Doesn’t support goto instructions Doesn’t contain side-effect expression operators Doesn’t support pointers or pointer arithmetic
6
Hello World indexing description: “Basic Hello World author : “Jim Developer” class HELLO_WORLD creation make feature make is do io.put_string ("Hello, world!%N") end
7
Basic Instructions Assignment Object Creation Routine Call Conditional Iteration Choice/Switch/Case
8
Assignment i := i + 1 Assignments cannot happen directly to class attributes. Methods/Routines must be used. Shortcut Assignments don’t exist
9
Object Creation Declaration acc:ACCOUNT acc is “void” when declared At runtime acc obtains an object by calling create acc Which creates a new instance of ACCOUNT and attaches acc acc can now be used: acc.open(“John”) acc.deposit(5000)
10
Data Types The following data types exist, the initialization of variables of these types is automatically initialized INTEGER initializes to zero REAL and DOUBLE initialize to 0.0 BOOLEAN initializes to false CHARACTER initializes to null Reference types initialize to a null reference INTEGER, REAL, DOUBLE, BOOLEAN and CHARACTER are all considered Expanded types
11
Reference Types A reference is the default object type, when an instance of a class is created it is called a reference, this is created by either calling “create” or using “!!”
12
Expanded Types An expanded type is one that is already initialized INTEGER, REAL, DOUBLE, BOOLEAN and CHARACTER are all considered Expanded types Expanded types don’t require calling “create” or “!!” If the class is not defined with the keyword “expanded” then it will be a reference type. expanded class INTEGER feature... end -- INTEGER
13
Routine/Function Call acc.open ("Jill") acc.deposit (5000) if acc.may_withdraw(3000) then acc.withdraw(3000);print(acc.balance) end
14
Conditional if x > 10 then... statements... elseif x > 5 then... elsif statements... elseif x > 0 then... more elsif statements... else... else statements... end
15
Looping/Iteration Only one looping statement exists, but it could be used to emulate other types of loops. For Loop from i := 1 until i = 10 loop io.put_int (i); io.new_line; i := i + 1; end While Loop from node := first; until node = Void; loop io.put_string (node.text); node := node.next; end; Repeat Loop from done := False until done and pages = 10; loop done := True; printer.output_next; pages := pages + 1; end
16
Choice/Switch/Case State : INTEGER; State_1, State_2, State_3 : INTEGER is unique;... statements... inspect State when State_1 then... statements... when State_2 then... statements... when State_3 then... statements... else... statements... end; The inspected value must be enumerable
17
Generic Classes class STACK [T] feature push( element : T ) is do storage( pos ) := element; pos := pos + 1; end -- push end -- STACK class LUNCH_COUNTER feature tray_stack : STACK[ TRAY ]; napkin_dispenser : STACK[ NAPKIN ]... init is do... napkin_dispenser.pop( end -- init end -- LUNCH_COUNTER
18
Creation Routines/Constructors class CONVERTER creation make; feature temperature : DOUBLE make is do temperature := 98.6; end -- make... end -- CONVERTER A creation routine is called when the reference type is created with “create” or “!!”
19
Exception Handling Exceptions can be thrown in few cases: Design by contract failures Low level functions Rescue (Catch) Retry (can only exist within a rescue clause) Retry starts execution of the routine again without the variable initialization
20
Exception Handling (Cont.) read_next_character (f: FILE) is -- Make next character available in last_character ; -- if impossible, set failed to True. require readable: file. readable local impossible: BOOLEAN do if impossible then failed := True else last_character := low_level_read_function ( f ) end rescue impossible := True retry end
21
Design By Contract Facilitates more reliable techniques Defines correct usage Assertions (Boolean Expression): Precondition (require) Postcondition (ensure) Class invariants (invariant) Class invariant must be satisfied upon exit of the creation procedure (constructor)
22
Assertion Monitoring Assertion monitoring levels are set at compile time The levels vary from no monitoring to monitoring all require/ensure/invariant Exceptions will be thrown if assertions are being monitored If the exception isn’t handled, a run-time error will result
23
Sample DBC indexing description: "Simple bank accounts" class ACCOUNT feature -- Access balance: INTEGER -- Current balance deposit_count: INTEGER is -- Number of deposits made since opening do … As before … end feature -- Element change deposit (sum: INTEGER) is -- Add sum to account. require non_negative: sum >= 0 do … As before … ensure one_more_deposit: deposit_count = old deposit_count + 1 updated: balance = old balance + sum end
24
Sample DBC (Cont.) feature { NONE } -- Implementation all_deposits: DEPOSIT_LIST invariant consistent_balance: (all_deposits /= Void) implies (balance = all_deposits. total) zero_if_no_deposits: (all_deposits = Void) implies (balance = 0) end -- class ACCOUNT
25
Object Oriented Purely Object Oriented Everything is an object Information Hiding Encapsulation Polymorphism/Dynamic Binding Inheritance (Including Multiple)
26
Object Oriented (Cont.) Supports information hiding/encapsulation No attributes of a class are allowed to be modified directly. All modifications must happen within a subroutine No global variables are allowed No static functions are allowed Secret attributes/routines are equivalent to private variables/methods
27
Polymorphism Dynamic binding allows polymorphic object to call the appropriate versioned routine acc : ACCOUNT ; sav : SAVINGS_ACCOUNT acc := sav acc.deposit( 1000 )
28
Inheritance Inheritance is supported Multiple inheritance is supported Routine can be overridden (redefine) Parent is known as a precursor Keyword precursor can be used to reference the parent Renaming allows conflicts with multiple inheritance to be resolved
29
Inheritance (Cont.) indexing description: "Savings accounts" class SAVINGS_ACCOUNT inherit ACCOUNT redefine deposit end feature -- Element change deposit ( sum : INTEGER ) is -- Add sum to account. do precursor (sum) … end … Other features … end -- class SAVINGS_ACCOUNT
30
Inheritance (Cont.) The implementation of inheritance supplies many keywords to define how the parents members are recognized Rename allows renaming of a parent attribute/routine Export allows changing protection of a parent attribute/routine Redefine allows overriding a routine Undefine allows removing a routine
31
Inheritance (Cont.) class D inherit A rename g as f -- g was effective in A export {X, Y, …} feature1, feature2 undefine f end B undefine f end -- f was effective in B C -- C also has an effective feature f, which will serve as -- implementation for the result of the join. feature …
32
In-Class Documentation Keyword Indexing Indexing Items (author, description, other) Developer defined indexing items Developer tools exist to generate documentation
33
class ACCOUNT feature balance: INTEGER -- Attribute owner: PERSON minimum_balance: INTEGER is 1000 open (who: PERSON) is -- Routine -- Assign the account to owner who. do owner := who end deposit (sum: INTEGER) is -- Deposit sum into the account. do add (sum) end withdraw (sum: INTEGER) is -- Withdraw sum from the account. do add (-sum) end may_withdraw (sum: INTEGER): BOOLEAN is -- Function -- Is there enough money to withdraw sum? do Result := (balance >= sum + minimum_balance) –- Return value end feature {NONE} add (sum: INTEGER) is –- Private/Secret Routine -- Add sum to the balance. do balance := balance + sum end end -- class ACCOUNT
34
Bibliography http://en.wikipedia.org/wiki/Eiffel_program ming_language http://archive.eiffel.com/doc/online/eiffel50/ intro/language/ http://www.eiffel.com/index.html http://www.comp.ufla.br/~monserrat/eiffel/ advanced_introduction/eiffel.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.