topical media & game development

talk show tell print

object-oriented programming

The language Eiffel

The language Eiffel has been designed with a clear concern for correctness and validation. It supports a bottom-up development approach, centered around the design of robust classes. Along with the language,  [Meyer88] introduces the notion of contracts as a means to specify the mutual obligations between the user of an object and the object in terms of a client/server relation.

Eiffel -- a language with assertions


  • bottom-up development -- class design
  • contracts -- specify client/server relationships

Design principles -- correctness

  • static typing -- type secure
  • multiple inheritance -- polymorphism
  • dynamic binding -- refinement
  • generic classes -- abstraction

slide: The language Eiffel

Eiffel is a (type secure) statically typed language, providing multiple inheritance and generic classes. Recently, Eiffel-3 has been introduced, supporting a number of features (such as overloading) inspired by C++. See  [Eiffel3].


The design of Eiffel also reflects a concern with the software engineering issues involved in the development and maintenance of class libraries. The language is built around a number of keywords, which accounts for an easy to read, albeit somewhat verbose, layout of programs.

The language Eiffel -- keywords

  • class -- a model for a set of objects
  • feature -- attribute, function, procedure
  • export -- interface declaration
  • inherit -- class inclusion and subtyping (!)
  • redefine, rename -- to change inherited features
  • deferred -- to postpone the implementation
  • require, ensure, invariant -- assertions

slide: Eiffel -- terminology

The keyword class precedes a class definition, which, according to  [Meyer88], may be considered as a model for a collection of objects. The keyword feature precedes the attributes, functions and procedures defined by a class. The keyword export precedes the list of visible features, in other words the interface declaration of the class. The keyword inherit precedes the list of inherited classes, specifying class inclusion and the subtyping relationships. The keywords rename and redefine are used to change inherited features. The keyword deferred may be used to indicate that a feature will be implemented (in the future) in an inherited class, and the keyword obsolete may be used to indicate that a feature will not be supported in a future release. Finally, the keywords require, ensure and invariant indicate assertions that specify respectively the pre- and post-conditions for a (method) feature and the class invariant.

Type expressions -- conformance

  • basic types -- Boolean, Integer
  • formal parameter types -- Array[T], List[T]
  • class types -- user-defined
  • anchored types -- like current

Value expressions

  • arithmetic, comparison, method evaluation -- o.m(...)


  • var := expression

slide: Eiffel -- type expressions


Eiffel is a strongly typed language. In Eiffel, variables must be explicitly typed by means of a declaration involving type expressions. Type expressions range over basic types (such as Boolean and Integer), formal type parameters of generic types (as the T in Array[T], which stands for the type of the elements of the array), class types (that are defined by the user) and anchored types, for instance like current (which results in the type of the current object, or self in Smalltalk terminology). Anchored types present some problems for the type safety of Eiffel programs. See section self-reference for a discussion.

In  [Meyer88] conformance rules are specified which are used to determine whether a given type is a subtype of another type. See section subtypes for an extensive discussion of the subtyping relationship.

Value expressions in Eiffel comprise the familiar arithmetical and comparison operations, as well as the message expressions of the form o.m(...) that result in the evaluation of the method m by the object o. Parameter passing in Eiffel is positional. See slide eiffel-expr.

Control structures

Control in Eiffel is meant to be effected primarily by defining (and redefining) the appropriate classes. However, control constructs both for branching and iteration are provided. See slide eiffel-control.

Control -- method refinement

  • branching -- if ... then ... elsif ... else ... end
  • iterations -- from ... until ... loop ... end

slide: Eiffel -- control

The if-statement has a classical form, as in Pascal. The iteration-statement may be used in a variety of ways, as a for-loop and as a while-statement (by omitting the from) part).


Objects in Eiffel are defined by classes. A typical class definition is given in slide eiffel-objects. The class counter exports the features inc and val. The feature count is hence private to an instance of counter, since it does not appear in the interface defined by the export part.

    class  counter  export  inc val  feature 
   count : Integer
   create  is do  count := 0  end 
   inc( n : Integer )  is 
  	 require  n > 0  do 
  	count := count + n
  	 ensure  count =  old  count + n
   val : Integer  is do   Result  := count  end 
    invariant  count >= 0
    end  -- class counter

slide: Eiffel -- objects

The create feature is automatically exported, and is used to create an instance of counter by the statement x.create for a variable x of type counter. The reserved word Result is used to return a value from a function feature. The method feature inc specifies both a pre-condition and a post-condition. The reserved word old is used to access the value of the instance variable count before evaluating inc. Finally, the invariance states the constraint that a counter instance never has a value below zero.


Eiffel supports multiple inheritance. As an example, look at the class FixedList in slide eiffel-inheritance, which is implemented as a combination (by inheritance) of a generic List and a generic Array.

Multiple inheritance

  class Fixed_List[T] export ...

slide: Eiffel -- inheritance

Using (multiple) inheritance implies that a FixedList may be regarded as a subtype of both Array and List. However, the export list in the end determines what interface is provided and hence what type the class embodies.


Developing programs in Eiffel is meant to be primarily a matter of modeling, that is designing classes and the (inheritance) relations between classes. An essential ingredient of class development is the design of appropriate interfaces.

Rename and/or redefine

  class C export ... inherit
    A rename   m   as m1 redefine p
    B rename   m   as m2 redefine q

slide: Eiffel -- techniques

To define a class as (derived from) a combination of classes, Eiffel allows both the renaming and redefinition of inherited features. See slide eiffel-tech. In  [Meyer88], many practical hints are given and numerous examples employing these mechanisms.


This section has given an introduction to the Eiffel language. It discussed the design principles underlying Eiffel, which may be characterized as being focused on static typing and support for the development of reliable programs.

The language Eiffel


  • design principles -- correctness
  • terminology -- keywords
  • syntax -- type conformance, control
  • objects -- counter example
  • inheritance -- renaming, redefining

slide: Eiffel -- summary

Further, it presented an overview of the keywords related to the constructs offered, and discussed type expressions, value expressions and control statements. An example was given to illustrate the features offered. Finally, we looked at the mechanisms of renaming and redefining, which are needed to avoid name clashes when using multiple inheritance.

(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.