Search This Blog

Sunday, 9 October 2011

Structured Vs. Object Oriented Programming

0 comments
Software development is a process of creating new software or modifying existing software that will meet the current requirements of its users.  This process consists of various stages or phases in it.  They are:
  1. Problem Definition (Analysis)
  2. Program Design
  3. Coding / Implementation
  4. Testing and
  5. Maintenance
A complete set of all these activities involved in developing software is known as Software Development Life Cycle (SDLC).  This is because the same sequence of steps are to be followed whenever we develop new software from scratch or modifying existing software for up gradation.

Some small programs like text editor (e.g., Notepad) can be coded directly without following all the steps involved in SDLC.  But, large programs like MS Word or MS Excel involve complexity in areas like understanding the problem domain, meeting the customer needs and delivering a good quality product in time.

To overcome the complexities involved in software development, many methodologies, tools and languages were introduced.  Following are two major methodologies introduced for simplifying software development process:
  1. Structured (Procedural) Programming
  2. Object Oriented Programming (OOP)
Structured Programming:
In structured programming model, software designers tend to use Top-Down approach, in which the overall objective of the system is defined first.  Then the system is divided into various sub tasks or sub modules.  With this methodology, software development is done by writing a set of sub programs, called functions that can be integrated together to form a complex system.

In Structured programming, the primary focus is on functions.  A function is a sub program that performs a specific task using the values given to it through input variables (called parameters) and then returns the result to its calling program.  Each function consists of a set of program statements and some local variables.  

A typical program structure for structured approach is shown below:


Fig. : Typical structure of Structure (Procedure) Oriented programs

A function when invoked behaves as though its code is inserted at the point of its call.  The communication between the caller (calling function) and the callee (called function) takes place through parameters.

At the time of function call, the control is transferred from the caller to the first statement of the callee.  All the statements in the function body are executed and then the control is transferred back to the caller to resume the execution of other statements.

Some characteristics exhibited by Structured or Procedural-oriented approach are:
  1. Emphasis is on doing things (algorithms)
  2. Large programs are divided into smaller programs called functions.
  3. Most of the functions share global data.
  4. Data move openly around the system from function to function and
  5. Employs Top-down approach in program design
Limitations of Structured Programming:

Structured programming was a powerful tool that enabled programmers to write moderately complex programs fairly easily.  However, as the programs grew larger, this approach failed to show the desired results in terms of bug-free, easy-to-maintain and reusability of programs.

In this approach, very little attention is given to data used by the function.  And, in a multi-function program, many important data items are placed in the global scope, so that they may be accessed by all functions.  But, this leads to the problem of accidental modification of data due to its access from various functions of the program.  Hence, in a large program it is difficult to keep track of the data items having global scope.

The following picture depicts the relationship of data and function in structured (or) procedural programming:


Fig. :  Relationship of data and functions in Structured programming

Another series drawback with the procedural approach is that it does not model the real world entities to the elements in a program in a one-to-one manner.  This is because the functions are action-oriented and they do not really correspond to the elements of the problem.

Object Oriented Programming:

Object Oriented Programming is centered on new concepts such as objects, classes, polymorphism, and inheritance.  OOP is defined as follows:  It is a method of programming in which programs are organized as co-operative collections of objects, each of which represents an instance of some class and whose classes are all members of a hierarchy of classes united through the property called inheritance.

In this approach, any real world entity can be modeled as an object.  The whole software is considered as a group of objects that work together to accomplish a particular task.  During execution, objects interact with each other by sending messages and receiving responses.

For instance, in a program that performs withdrawal from an account, a customer object may send a withdraw message to a bank account object in order to perform a withdrawal operation.  Any object that communicates with another object need not be aware of its internal workings but only its function signatures.

Leave a Reply