Procedural Programming

In procedural programming (i.e. C), a problem is broken down into subproblems. These are solved separately in modules, so-called functions respectively procedures). A procedure contains a sequence of statements, such as assignments, tests, loops and invokations of sub procedures with defined input and output.

Procedures process data that has been passed to them via parameter lists as interfaces.

Originally, computers were used almost exclusively to solve tasks whose scope and complexity was relatively limited. The programs were still relatively small (measured by today's standards). For this purpose, the programming concept of procedural programming was quite sufficient.
However, with increasing computer power, the size and complexity of the programs also grew very much. The computer made a change to a universal work tool. Today the applications extend over areas such as e.g. multimedia, artificial intelligence and communication.
This requires a greater overview in programming, or more program structure.

This changes required a rethinking of the programming concept as well:

Object-oriented Programming


The real world does not only consist of processes that can be well represented in the abstract procedural way. (Programs always represent reality somehow.)

First of all, the world consists of things, objects, persons, etc., which it has to consider and thus put into the foreground. These objects have certain properties and interact with each other in a certain way.

Objects use their own methods to process their own data (properties).

If object data (properties) can only be changed via a method of the object itself and never directly, this is called data encapsulation:

Object
Object


automated teller machine ATMExample

The "money supply" feature of an ATM (automated teller machine) can only be changed by a "pay in and out" method exactly of that ATM. It can not be changed directly, which greatly increases program security. The money supply of the neighboring machine is only changeable through the methods "pay in and out" of this neighboring machine.









 1 public class AutomatedTellerMachine {
 2     private double moneySupply;          // encapsulated property: in all methods of class accessible
 3 
 4     public double payOut(double amount)  // Definition of method payOut (must be accessible from elsewhere => public
 5     {
 6         if (moneySupply >= amount)
 7         {
 8             moneySupply -= amount;
 9             return amount;
10         }
11         else
12             return -1;                   // error code
13     }
14 
15     public void payIn(double amount)
16     {
17         moneySupply += amount;
18     }
19 }

 1 public class Main {
 2 
 3     public static void main(String[] args) {
 4 
 5         AutomatedTellerMachine atm1 = new AutomatedTellerMachine(); // Creation of object atm1
 6                                                                     // of class AutomatedTellerMachine
 7         atm1.payIn(1000);  // Invokation of method payIn of object atm1
 8 
 9         System.out.println(atm1.payOut(100));
10     }
11 }


Object-oriented Programming
Procedural Programming
+ Real world consists of objects, therefore better portability of reality.
+ Data encapsulation protects the properties of an object.
+ More structure => more clarity => better maintainability etc.
+ Reuse of programming code through inheritance is possible.
+ Slightly less source code for small programs,
+ Slightly more performance (speed) for interpreter languages

Last modified: Monday, 16 September 2019, 9:06 PM