Can anyone explain me what is the difference between procedural programming and Object-Oriented programming.
When designing a complex software system, we decompose it into smaller parts.
In procedural programming, we decompose the system into steps and sub-steps in some overall process.
//Global data module
struct A { int x; }; //data type definition
struct B { int y; };
A a; //data is allocated
B b;
//Main module
void Program()
{
initialize(); //function calls
doInputStep();
doComputeStep();
doOutputStep();
}
//Input module
void doInputStep() {...} //function definition
//Processing module
void doComputeStep() //function definition
{
doPart1(); //function calls
doPart2();
doPart3();
}
void doPart1() {...} //function definitions
void doPart2() {...}
void doPart3() {...}
//Output module
void doOutputStep() {...} //function definition
In object-oriented programming, we decompose the system according to the key abstractions of the problem domain.
class ConceptA {
int x; //data is allocated
void compute() {...} //function definition
void output() {...}
}
class ConceptB {
int y;
void compute(ConceptA a) {...}
void output(ConceptA a) {...}
}
class Program {
public static void main(
String[] args) {
ConceptA a = new ConceptA();
a.compute(); a.output();
}}
In procedural programming, control is centralized. One procedure gets data from other procedures and computes. In object-oriented programming, control is distributed. If object A is computing and object B has the data, instead of asking B for the data, object A gives control to object B.
In procedural programming, the system is viewed as a process. Procedures are steps and sub-steps in the process. In object-oriented programming, the system is viewed as a set of autonomous agents that collaborate to perform some higher level behavior.
[ November 28, 2004: Message edited by: Marlene Miller ]