Illustrative image which says: Object oriented programming
Index

Oject oriented programming

Object oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

In OOP, computer programs are designed by making them out of objects that interact with one another.

Illustrative image for the object oriented programming in which apeeear one car in a column which says class and another three cars, green, blue and red as objects

In addition to classes and objects, there are four major pillars in OOP:

  • Encapsulation: Binds or combines properties and methods into a single unit.
  • Inheritance: Allows a class to use properties and methods of an already existing class.
  • Polymorphism: Allows an object to perform in multiple ways – Overloading and overriding are two ways of achieving polymorphism.
  • Abstraction: Hides the internal details and displays only the functionalities to the user – Moreover, abstract classes and interfaces help to achieve abstraction.

Overall, object oriented programming makes it easier to develop the program. Furthermore, it provides data security, maintainability and code reusability.

Structured programming

Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines.

Structured Programming divides a program into a set of functions or modules which have statements embraced inside curly braces and each of them perfom a subtask. Usually, as each function represents a specific functionality, it is easier for the programmer to test and debug the code, but this can differ depending on the program.

Illustrative image for structured programming

In the structured programming C, the user can create his own user-defined functions. The main function calls the other functions and indicates the execution of the program. When there is a function call, the control is passed to that function. After completing the function, the control passes back to the main program. Moreover, a variable inside a function is a local variable, and global variables are accessible by all the functions.

Differences between them

Table with the differences metioned before

Definition

Structured programming is a programming paradigm which divides the code into modules or function, while OOP is a programming paradigm based on the concept of objects, which contain data in the form of fields known as attributes, and code in the form of procedures known as methods.

Main focus

Structured programming focuses on dividing the program into a set of functions in which each function works as a subprogram while object oriented programming focuses on representing a program using a set of objects which encapsulates data and object.

Modification

It is easier to modify the Object Oriented programs than structured programs.

Communication

In structured programming, the main method communicates with the functions by calling those functions in the main program whereas, in object oriented programming, the objects communicate with each other by passing messages. Hence, this is an important difference between structured and object oriented programming.

Access specifiers

There are no access specifiers in structured programming while there are access specifiers such as private, public and protected in Object Oriented Programming. Thus, this is also an important difference between structured and object oriented programming.

Security

Data is not secure in structured programming, but it is secure in object oriented programming.

Code reusability

It is easier to reuse code in object oriented programming than in structured porgramming.