gerry
Uploaded by
17 SLIDES
336 VUES
180LIKES

Introduction to Concurrent Object-Oriented Programming in Eiffel

DESCRIPTION

This exercise session, led by Prof. Dr. Bertrand Meyer, provides an overview of the Eiffel programming language and its concurrent object-oriented programming capabilities. It covers fundamental concepts such as multiple inheritance, feature adaptation, generic classes, and contracts. The session includes practical examples, including creating numeric comparable value holders, reading and writing to the console, and understanding deferred classes. Participants will learn how to leverage EiffelStudio for code writing, compilation, and debugging, enhancing their programming skills in a structured environment.

1 / 17

Télécharger la présentation

Introduction to Concurrent Object-Oriented Programming in Eiffel

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript

Playing audio...

  1. Concurrent Object-Oriented ProgrammingProf. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction

  2. Overview • Eiffel • EiffelStudio

  3. Eiffel: Classes class NUMERIC_COMPARABLE_VALUE_HOLDER inherit A B end Eiffel supports multiple inheritance. Potential name clashes can be resolved through feature adaption.

  4. Eiffel: Features inherit ... feature {APPLICATION, NUMERIC_COMPARABLE_VALUE_HOLDER} value: INTEGER assignset_value set_value (a_value: likevalue) do value := a_value end sum_of_values (a_value: like value): like value local l_value: likevalue do l_value := value + a_value Result := l_value end export status: The default is ANY. attribute with assigner procedure routine anchored type function routine Routines (procedures, functions) can have local variables. current object

  5. Eiffel: Creation Procedures inherit ... create {APPLICATION, NUMERIC_COMPARABLE_VALUE_HOLDER} set_value feature ... export status: The default is ANY. list of procedure to be used as creation procedures

  6. Eiffel: Further Instructions sum_of_value_holders (a_value_holder: likeCurrent): likeCurrent local l_value_holder: likeCurrent do createl_value_holder.set_value (value + a_value_holder.value) Result := l_value_holder end creation assignment implicit result variable

  7. Eiffel: Further Instructions multiplication_of_values (a_value: like value): like value local l_counter: like value do from Result := value.zero l_counter := value.zero until l_counter.is_equal (a_value) loop if a_value >= value.zero then Result := Result + value l_counter := l_counter + value.one else Result := Result - value l_counter := l_counter - value.one end end end loop initialization loop exit condition loop body

  8. Eiffel: Contracts • feature • ... set_value (a_value: likevalue) require value_is_not_zero: not a_value.is_equal (value.zero) do ... ensure value_is_set: value = a_value end • invariant • value_is_not_zero: not value.is_equal (value.zero) precondition postcondition invariant

  9. Eiffel: Genericity class NUMERIC_COMPARABLE_VALUE_HOLDER [T->{NUMERIC renameis_equalasnumeric_is_equalend, COMPARABLE}] ... feature value: T assignset_value ... end the second constraint: T needs to conform to COMPARABLE. formal generic parameter the first constraint: T needs to conform to NUMERIC. is_equal gets renamed because COMPARABLE has a conflicting feature. • l_integer_value_holder: NUMERIC_COMPARABLE_VALUE_HOLDER[INTEGER] • create l_integer_value_holder.set_value (1) actual generic parameter

  10. Eiffel: Console I/O Read an integer from the console and make it accessible through io.last_integer. • io.read_integer • io.put_integer (io.last_integer) • io.new_line Write an integer to the console. Start a new line on the console.

  11. Eiffel: Deferred Classes and Features deferred class • deferredclassNUMERIC_COMPARABLE_VALUE_PRINTER • [T -> {NUMERICrenameis_equalasnumeric_is_equalend, COMPARABLE}] • inherit • NUMERIC_COMPARABLE_VALUE_HOLDER[T] • feature • print_value • deferred • end • print_value_multiple_times (a_number: NATURAL) • local • l_counter: likea_number • do • from • l_counter := a_number.zero • until • l_counter = a_number • loop • print_value • io.put_new_line • l_counter := l_counter + a_number.one • end • end • end deferred feature A deferred class can have effective features which rely on deferred features.

  12. Eiffel: Frozen and Expanded Classes frozen class • frozen expanded class INTEGER • inherit • NUMERIC • ... • COMPARABLE • ... • feature • ... • end expanded class

  13. EiffelStudio • EiffelStudio is an IDE for Eiffel. • components • editor • context tool • clusters pane • features pane • compiler • project settings • ...

  14. EiffelStudio: Writing Code • syntax highlighting • class name completion (SHIFT+CTRL+space) • smart indenting • block indent or exdent (TAB and SHIFT+TAB) • block commenting or uncommenting (CTRL+K and SHIFT+CTRL+K) • infinite level of undo/redo (reset after a save) • quick search features (first CTRL+F to enter words then F3 and SHIFT+F3)

  15. EiffelStudio: Compiling • uses incremental compilation • freezing: Generates C code from the whole system and then compiles it to machine code. This code is used during development. Initially the system is frozen. • melting: Generates bytecode for the changed parts of the system. This is much faster than freezing. This code is used during development. • finalizing: Creates an executable production version. Finalization performs extensive time and space optimizations.

  16. EiffelStudio: Debugging • The system must be melted/frozen (finalized systems cannot be debugged). • Set / delete breakpoints. An efficient way of adding breakpoints consists in dropping a feature in the context tool. • Run the program or step over / into the first statement. Pause or wait for a triggered breakpoint. • Analyze the program. • Use the object tool and the call stack pane. • Run the program or step over / into the next statement. • Stop the running program.

  17. Resources • http://www.eiffel.com/ • http://docs.eiffel.com/ • http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-367.pdf

More Related