This post is for the sake of remembering and learning the basics of Eiffel.......................
You can create classes like any other oo language, in Eiffel.
Before anything here's famous "Hello World"
class Hello
create
make
feature
make is
print("Hello world")
end -- end make
end -- end class
create = constructor
feature = instance var, methods
is = definition of feature
(is - end) = a block - { code goes here}
Compared with java, similar to instance variables, and methods Eiffel has "Features"
Features are divided into 3 sections
Procedures : change state of a attribute
Functions : return answer to a query of a state of a object, do not change state
Attribute : the states of the object considered are declared there
routines : Procedures+ (computational) Functions
simple declarations
size : INTEGER
name : STRING
myList : ARRAY[TYPE]
simple procedure
set_size(s: like size) is do size := s end
simple function
get_size : INTEGER is do Result := size end
Note: here Result is always the return value for a function
create an instance from another class
create make_duck(size)
additional to these simple facts,
keywords such as require and ensure enable to have pre and post conditions for a specific function or procedure, this restring the false conditions that might occur when passing arguments.
Tested with EiffelStudio 6.6
[Reference: http://eiffelzone.com/doc/into-eiffel.html
Eiffel: The Essentials by Meyer]
No comments:
Post a Comment