Page 198 - DCAP104_EXPOSURE_TO_COMPUTER_DISCPLINES
P. 198
Unit 9: Software Development
of a specific class. This allows later code to use the same function exchanging different object Notes
types; hence such code turns out to be more generic and reusable.
Usually a method in an interface cannot be used directly; there must be a class implementing
that object to be used for the method invocation. For example, one can define an interface called
“Stack” that has two methods: push( ) and pop( ) and later implement it in two different versions,
say, FastStack and GenericStack-the first being faster but working with a stack of fixed size, and
the second using a data structure that can be resized but at the cost of somewhat lower speed.
This approach can be pushed to the limit of defining interfaces with a single method; e.g. the
Java language defines the interface Readable that has the single read( ) method and a collection
of implementations to be used for different purposes, among others: BufferedReader, FileReader,
InputStreamReader, PipedReader, and StringReader.
In its purest form, an interface (like in Java) must include only method
definitions and constant values that make up part of the static interface of a
type. Some languages (like C#) also permit the definition to include properties
owned by the object, which are treated as methods with syntactic sugar.
9.2.1.3 Programming against Software Interfaces
The use of interfaces allows implementation of a programming style called programming against
interfaces. The idea behind this is to base the logic one develops on the sole interface definition
of the objects one uses and not to make the code depend on the internal details. This allows the
programmer the ability to later change the behavior of the system by simply swapping the object
used with another implementing the same interface.
Pushing this idea to the limit one can introduce the inversion of control which means leaving
the context to inject the code with the specific implementations of the interface that will be used
to perform the work.
9.2.2 Hardware Interfaces
Hardware interfaces exist in computing systems between many of the components such as the
various buses, storage devices, other I/O devices, etc. A hardware interface is described by the
mechanical, electrical and logical signals at the interface and the protocol for sequencing them
(sometimes called signaling). A standard interface, such as SCSI, decouples the design and
introduction of computing hardware, such as I/O devices, from the design and introduction
of other components of a computing system, thereby allowing users and manufacturers great
flexibility in the implementation of computing systems.
9.3 Planning a Computer Program
9.3.1 The Programming Process
Developing a program involves steps similar to any problem-solving task. There are five main
ingredients in the programming process:
1. Defining the problem
2. Planning the solution
3. Coding the program
4. Testing the program
5. Documenting the program
Let us discuss each of these in turn.
LOVELY PROFESSIONAL UNIVERSITY 191