Eiffel Programming Language. Chad Frommeyer CSC 407/507 Fall 2005 Dr. Richard Fox.

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Advertisements

Programming Languages and Paradigms
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction.
Written by: Dr. JJ Shepherd
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Software Architecture Prof. Dr. Bertrand Meyer Lecture 6: Exception Handling.
Design by Contract ™. 2 Design by Contract A discipline of analysis, design, implementation, management.
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
Software Engineering and Design Principles Chapter 1.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
Chair of Software Engineering ATOT - Lecture 25, 30 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 15: Exception handling.
-5- Exception handling What is an exception? “An abnormal event” Not a very precise definition Informally: something that you don’t want to happen.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology Bertrand Meyer.
Principles of Object-Oriented Software Development The language Eiffel.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 12: Design by Contract™
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 9: Contracts and Inheritance (based on work with.
Chair of Software Engineering ATOT - Lecture 11, 7 May Advanced Topics in Object Technology Bertrand Meyer.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Lecture 9 Concepts of Programming Languages
C++ fundamentals.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
1 Prototype-basedPrototype-based scripting languagescripting language.
OOP Languages: Java vs C++
Ranga Rodrigo. Class is central to object oriented programming.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Tammy Dahlgren with Tom Epperly, Scott Kohn, and Gary Kumfert Center for Applied Scientific Computing Common Component Architecture Working Group October.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
1 Exceptions When the Contract is Broken. 2 Definitions A routine call succeeds if it terminates its execution in a state satisfying its contract A routine.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Design issues for Object-Oriented Languages
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
About the Presentations
Java Programming Language
MSIS 670 Object-Oriented Software Engineering
Object-Oriented Programming
CISC/CMPE320 - Prof. McLeod
Chapter 8: Class Relationships
Introduction to Programming
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Contract-Based Programming with/without Ada 2012
Design by Contract – Exceptions
Presentation transcript:

Eiffel Programming Language

Chad Frommeyer CSC 407/507 Fall 2005 Dr. Richard Fox

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

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

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

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

Basic Instructions Assignment Object Creation Routine Call Conditional Iteration Choice/Switch/Case

Assignment i := i + 1 Assignments cannot happen directly to class attributes. Methods/Routines must be used. Shortcut Assignments don’t exist

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)

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

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 “!!”

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

Routine/Function Call acc.open ("Jill") acc.deposit (5000) if acc.may_withdraw(3000) then acc.withdraw(3000);print(acc.balance) end

Conditional if x > 10 then... statements... elseif x > 5 then... elsif statements... elseif x > 0 then... more elsif statements... else... else statements... end

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

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

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

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 “!!”

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

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

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)

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

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

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

Object Oriented Purely Object Oriented Everything is an object Information Hiding Encapsulation Polymorphism/Dynamic Binding Inheritance (Including Multiple)

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

Polymorphism Dynamic binding allows polymorphic object to call the appropriate versioned routine acc : ACCOUNT ; sav : SAVINGS_ACCOUNT acc := sav acc.deposit( 1000 )

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

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

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

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 …

In-Class Documentation Keyword Indexing Indexing Items (author, description, other) Developer defined indexing items Developer tools exist to generate documentation

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

Bibliography ming_language intro/language/ advanced_introduction/eiffel.html