Previous | Table of Contents | Next |
The subsequent sections show how to write Eiffel classes with their features. In an Eiffel system, however, not everything has to be written in Eiffel: Some features may be external, coming from external languages such as C, C++, Java, Fortran, or others. For example, a feature declaration may appear (in lieu of the forms seen later in this chapter) as
file_status ( filedesc: INTEGER): INTEGER is -- Status indicator for filedesc external C alias _fstat end
to indicate that it is actually an encapsulation of a C function whose original name is _fstatv. (The alias clause is optional, but here it is needed because the C name, starting with an underscore, is not valid as an Eiffel identifier.)
Similar syntax exists in several Eiffel compilers to interface with C++ classes. ISE Eiffel includes a tool called Legacy++, which automatically produces, from a C++ class, an Eiffel class that encapsulates its facilities, making them available to the rest of the Eiffel software as bona fide Eiffel features.
These mechanisms illustrate one of the roles of Eiffel: a system architecture and software composition tool, used at the highest level to produce systems with robust, flexible structures ready for extendibility, reusability. and maintainability. In these structures, not everything must be written in the Eiffel language: Existing software elements and library components can play their part too, with the structuring capabilities of Eiffel (classes, information hiding, inheritance, clusters, and other techniques in this chapter) serving as the overall wrapping mechanism.
A system with a certain static structure describes a set of possible executions. The runtime model governs the structure of the data (objects) created during such executions.
The properties of the runtime model are not just of interest to implementers; they also involve concepts directly relevant to the needs of system modelers and analysts at the most abstract levels.
A class is defined as the static description of a type of runtime data structure. The data structure described by a class is called an instance of the class, which in turn is called the generating class (or just generator). An instance of ACCOUNT is a data structure representing a bank account; an instance of LINKED_LIST is a data structure representing a linked list.
An object, as created during the execution of a system, is an instance of some class of the system.
Classes and objects belong to different worlds. A class is an element of the software text; an object is a data structure created during execution. Although it is possible to define a class whose instances represent classes (as class E_CLASS in the ISE libraries, used to access properties of classes at runtime), this does not eliminate the distinction between a static, compile-time notion, class, and a dynamic, runtime notion, object.
An object is either an atomic object (integer, real, boolean, or double) or a composite object made of a number of fields, represented by adjacent rectangles on the conventional runtime diagrams (see Figure 9.4).
FIGURE 9.4. A composite object with four fields, including self-reference and void reference.
Each field is a value. A value can be either an object or an object reference:
Previous | Table of Contents | Next |