Eiffel programming From Wikibooks, the open-content textbooks collection Jump to: navigation search Eiffel is a complete object-oriented language designed from the ground up to support object-oriented programming according to the design by contract (DbC) paradigm. This WikiBook introduces the fundamentals of Eiffel. Contents Classes Libraries Features ... edit Introduction edit Classes The basic construct in Eiffel is the class. In fact there is no other construct of note. So immediately we have a language which is fundamentally simpler than C/C++ and Object Pascal. A class represents entities, the attributes of those entities and the operations that those entities can perform. This gives you a fundamental mechanism for project organization because any application is organized into a set of interacting classes. Classes represent real world entities in a model, but can represent more artificial artifacts that occur only in computer programs. An example of an Eiffel class is: class CAR end A class represents all objects of that type. For instance, in the real world we have one concept of CAR, but there are many instances of CARs. We should be careful to distinguish between a class as a conceptual design pattern of entities and objects that represent the entities themselves. edit Libraries edit Features class CAR feature colour COLOUR a field velocity INTEGER is a function do Result speed end wheels INTEGER is a constant speed INTEGER stop is a procedure do speed end end CAR edit Inheritance Perhaps the distinguishing feature of object-oriented languagesâafter classesâto many people is inheritance. Simply put, inheritance is the ability to create a new class from an existing class. It only makes sense to do this when the existing class provides features wanted in the new class. Where features are not exactly what is required in the new class, they can be redefined. Redefinition can take two formsâeither redefinition of an operation or function, or redefinition of type. Redefinition of operation is only meaningful where the feature is a routine. Redefinition of type can be applied to fields, functions, and arguments In order to build new classes out of existing classes and to reuse features already defined in those classes, you use inheritance. In Eiffel, you use the inheritance clause as follows: | |
|