Page 15 - DCAP404 _Object Oriented Programming
P. 15
Object-oriented Programming
Notes
Figure 1.5: Typical Structure of Procedure-oriented Programs
Main function
Function-1 Function-2 Function-3
Function-4 Function-5
Function-6 Function-7 Function-8
Although data may be organized into structures, the primary focus is on functions. Each C
function transforms data in some way.
Example: You may have a function that calculates the average value of a set of numbers,
another that computes the square root, and one that prints a string.
You do not have to look far to find examples of this kind of programming – C function libraries
are implemented this way. Each function in a library performs a well-defined operation on its
input arguments and returns the transformed data as a return value. Arguments may be pointers
to data that the function directly alters or the function may have the effect of displaying graphics
on a video monitor.
A typical program structure for procedural programming is shown in Figure 1.5. The technique
of hierarchical decomposition has been used to specify the tasks to be completed in order to
solve a problem.
Procedure oriented programming basically consists of writing a list of instructions for the
computer to following and organizing these instructions into groups known as functions. We
normally use a flowchart to organize these actions and represent the flow of control from one
action to another.
While we concentrate on the development of functions, very little attention is given to the data
that are being used by various functions. What happens to the data? How are they affected by the
functions that work on them?
In a multi-function program, many important data items are placed as global so that they may
be accessed by all the functions. Each function may have its own local data. Figure 1.6 shows the
relationship of data and functions in a procedure-oriented program.
Global data are more vulnerable to an inadvertent change by a function. In a large program it is
very difficult to identify what data is used by which function. In case we need to revise an
external data structure, we should also revise all functions that access the data. This provides an
opportunity for bugs to creep in.
8 LOVELY PROFESSIONAL UNIVERSITY