Procedural Abstraction and Other Terms
(revised 02/13/2006)

Procedural Abstraction : The conceptual process whereby one ignores the details of how the code works and concentrates instead on the essentials of what the code does.  A practical implementation of procedural abstraction is seen in treating a function (or procedure) like a black box where the details of how the function works are hidden. The user of the function only needs to know what the functions does. Hiding details of implementation  is called information hiding which prevents the user from getting bogged down in the details (what you can't see can't hurt you) and prevents the user from subverting the implementation.

In general abstraction refers to ignoring the details and concentrating on the essentials.

Procedural Abstraction is a powerful tool that can be used to design programs. It allows you to concentrate on what a function should do (i.e. concentration on the essentials) and to ignore the details of how it's done.


Functions and Style : Functions should be designed like black boxes with prototype written so

  1. all function inputs (formal parameters) are well defined 
  2. all conditions for the function to execute correctly are clearly stated 
  3. the value returned is cleared described

Procedural abstraction (information hiding) is the reason why when defining a function, a distinction is made between its declaration (prototype) and its definition. The former (declaration) tells what the function does; it hides the details of implementation and allows the user to concentrate on the essentials. The details of implementation (how the function works) are placed in the definition part..


Function Overloading: Using the same name for different functions which perform similar tasks. C++ can distinguish between same named functions as long as the number and types of parameters differ.


Local Variables, Globals, and Scope

Variables declared within a function (or the main part of a program) are local to that function (or local to the main part of the program). Their scope or range of definition does not extend outside the body of the function. These are called local variables.


Global Constants are declared outside of the main part of a program and outside of all functions. The scope of a global constant (i.e. range of definition) extends into the main part of the program and all functions.

Global Variables which are also declared outside of the main part of a program and outside all functions should be avoided for two reasons

  1. values should be passed into a function only via parameters; global variables by-pass this method.
  2. global variables can cause un-wanted side effects - the accidental changing of a variable

Parameters

Parameters are used to pass information into (and out of) a function.

Formal Parameters - parameter used in the definition of a function. Formal parameters are local variables.

Actual Parameters - parameter used in the call of a function

Actual and Formal parameters MUST agree in number and type. Names mean nothing


Parameter Passing Mechanisms

Pass by Value : The value of the actual parameter is passed to the formal parameter. This is a one-way flow of data into a function. Actual pass by value parameters may be constants, literals, expressions, standard functions, or variables.

Pass by Reference : During the function call, the actual parameters and formal parameters are linked so that any change to one results in a change to the other. This is results a two-way flow of information between the calling functions and the called function. Pass by reference parameters are denoted by suffixing an & to the parameter type. Actual pass by reference parameters must be variables

Array Parameters : To make the passing of arrays efficient, arrays can only be passed using the pass by reference mechanism. That is, during the function call, the actual array parameter and the formal array parameter are linked so that any change to one results in a change to the other. This results in a two way flow of information between the calling function and the called function. The only difference between array parameters and pass by reference parameter is syntactic : array parameters do not use the &.  Array parameter must be arrays. If you want to prevent the actual parameter from being changed, a property of pass by value parameters, declare the formal parameter as a const parameter (e.g. const double list[]).


Logical Parameters - describing how a parameter is used

In Parameter: a parameter which is used to pass a value into a function.  These are usually implemented as "pass-by-value" parameters. 

Out Parameter:  a parameter which is used to pass a value out of a function. These are always implemented as "pass-by-reference" parameters.

In/Out Parameter: a  parameter which is used to pass a value into a function, the value is subsequently modified by the function and passed back out of the function. These are implemented as "pass-by-reference" parameters"


Return to Comp 150 Home Page