Software Quality

Download Report

Transcript Software Quality

Ranga Rodrigo
Class is central
to object
oriented
programming.
Hello World
class
HELLO
create
make
feature
make is
do
io.put_string("Hello, world!")
end
end
Hello World Class
 Eiffel programs are collections of classes.
 Executable code must be contained inside a routine. In
this example, make is a procedure in the HELLO class.
 make is designated as a creation procedure, or
constructor.
 To run a program, you must specify the root class
(HELLO) and the root feature from which execution will
start (make).
Hello World Class
is an attribute of the HELLO class inherited from an
implicit base class ANY.
 It is an instance of the class STD_FILES, which provides a
number of basic input and output routines, including
put_string to write a string to standard output.
 io
Class Structure
class CLASSNAME
-- various definitions
feature
-- feature definitions
end
Class Names and Features
 Class names are conventionally written in uppercase,
though Eiffel is not case sensitive.
 Comments start with -- and extend to the end of the
line.
 Features are classified as follows:
 Attributes: data members, or fields.
 Routines: member functions, methods, or operations.
Routines can be:
 Functions, which have a return type.
 Procedures, which don't have a return type. Procedures are
equivalent to functions in Java or C++ that return void.
Constructors
 Unlike Java or C++, there is no special syntax for
constructors.
 Any procedure can be used to initialize a new class
instance if it is declared as a creation procedure.
 The name make is commonly used for creation
procedures.
ANY
 All Eiffel classes are considered to be subclasses of
the class ANY.
 They therefore contain features from ANY, such as
the attribute io.
 This is similar to Java, where all classes are
considered to be subclasses of Object.
Eiffel Libraries
 The Eiffel Base Library defines basic types, data
structures, random numbers and so on.
 Library classes do not have to be explicitly imported
into an Eiffel text. Rather, a complete application is
defined as a number of clusters, typically:
 A cluster containing the libraries available to the
application, and
 The root cluster, containing the application code.
Basic Types
INTEGER
REAL
DOUBLE
BOOLEAN
CHARACTER
STRING
 They are defined as classes.
 They can be used much as
basic types in other languages.
 BOOLEAN: true or false.
 Character: single quotes,
 %N  newline,
 %U  null.
 Strings: double quotes.
Entities
 Entity is the Eiffel term for things that can hold data.
 Attributes of classes.
 Local variables within routines.
 Parameters of routines.
 Entities are defined by giving a name and a type
separated by a colon.
Entities
class COUNTER
feature
value : INTEGER
increment is
do
value := value + 1
end
end
This class does not have a
creation procedure: the
Eiffel ensures that the value
attribute will be initialized
to o.
Default Values of Entities
INTEGER: 0
REAL, DOUBLE: 0.0
BOOLEAN: false
CHARACTER: '%U'
STRING and other class types: Void
Using Classes
class
MAIN
create
make
Feature
c : COUNTER
make is
do
create c
io.put_string(c.value)
end
end
Using Classes
 MAIN contains an attribute which holds a reference to
an instance of class COUNTER.
 This attribute has the default value void.
 Before it can be used, a counter object must be created:
the Eiffel keyword for this is create, which has
basically the same effect as the Java/C++ operator new.
 As the counter class has no creation routine, no
arguments are required when creating a new object.