Page 197 - DCAP104_EXPOSURE_TO_COMPUTER_DISCPLINES
P. 197
Exposure to Computer Disciplines
Notes
Figure 9.6
9.2.1 Software Interfaces
A software interface may refer to a range of different types of interface at different “levels”: an
operating system may interface with pieces of hardware, applications or programs running on
the operating system may need to interact via streams, and in object oriented programs, objects
within an application may need to interact via methods.
9.2.1.1 Software Interfaces in Practice
A piece of software provides access to computer resources (such as memory, CPU, storage, etc.)
by its underlying computer system; the availability of these resources to other software can have
major ramifications sometimes disastrous ones for its functionality and stability. A key principle of
design is to prohibit access to all resources by default, allowing access only through well-defined
entry points, i.e. interfaces.
The types of access that interfaces provide between software components can include: constants,
data types, types of procedures, exception specifications and method signatures. In some instances,
it may be useful to define public variables as part of the interface. It often also specifies the
functionality of those procedures and methods, either by comments or (in some experimental
languages) by formal logical assertions and preconditions.
The interface of a software module A is deliberately kept separate from the implementation of
that module. The latter contains the actual code of the procedures and methods described in the
interface, as well as other “private” variables, procedures, etc.. Any other software module B
(which can be referred to as a client to A) that interacts with A is forced to do so only through the
interface. One practical advantage of this arrangement is that replacing the implementation of
A by another one that meets the same specifications of the interface should not cause B to fail-as
long as its use of A complies with the specifications of the interface.
9.2.1.2 Software Interfaces in Object Oriented Languages
In object-oriented languages the term “interface” is often used to define an abstract type that
contains no data but exposes behaviors defined as methods. A class having all the methods
corresponding to that interface is said to implement that interface. Furthermore, a class can
implement multiple interfaces, and hence can be of different types at the same time.
An interface is hence a type definition; anywhere an object can be exchanged (in a function or
method call) the type of the object to be exchanged can be defined in terms of an interface instead
190 LOVELY PROFESSIONAL UNIVERSITY