DEV Community

Sagar R Ravkhande
Sagar R Ravkhande

Posted on • Updated on

 

Object Oriented Programming (OOP) Concepts

The high-level programming languages are broadly categorized into two categories:

  • Procedure-oriented programming (POP) language.
  • Object-oriented programming (OOP) language.

Procedure-Oriented Programming Language

In the procedure-oriented approach, the problem is viewed as a sequence of things to be done such as reading, calculation, and printing.
Procedure-oriented programming consists of writing a list of instructions or actions for the computer to follow and organizing this instruction into groups known as functions.

POP

Characteristics of procedure-oriented programming:

  1. Emphasis is on doing things(algorithm)
  2. Large programs are divided into smaller programs known as functions.
  3. Most of the functions share global data
  4. Data move openly around the system from function to function
  5. Function transforms data from one form to another.
  6. Employs top-down approach in program design

The disadvantage of procedure-oriented programming languages is:

  1. Global data access
  2. It does not model real word problems very well
  3. No data hiding

Object Oriented Programing Language

“Object-oriented programming is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand”.

OOP

Characteristics of Object-Oriented programming:

  1. Emphasis is on doing rather than procedure.
  2. programs are divided into what are known as objects.
  3. Data structures are designed such that they characterize the objects.
  4. Functions that operate on the data of an object are tied together in the data structure.
  5. Data is hidden and can’t be accessed by external functions.
  6. Objects may communicate with each other through functions.
  7. New data and functions can be easily added.
  8. Follows bottom-up approach in program design.

Procedure Oriented Programming (POP) Vs Object Oriented Programming (OOP)

Procedure Oriented Programming Object Oriented Programming
Program is divided into small parts called functions. Program is divided into parts called objects.
Importance is not given to data but to functions as well as the sequence of actions to be done. Importance is given to the data rather than procedures or functions because it works in the real world.
Top-Down approach. Bottom-Up approach.
It does not have any access specifier. OOP has access specifiers named Public, Private, Protected, etc.
Data can move freely from function to function in the system. Objects can move and communicate with each other through member functions.
Adding new data and functions in POP is not so easy. OOP provides an easy way to add new data and functions.
Most function uses Global data for sharing that can be accessed freely from function to function in the system. In OOP, data cannot move easily from function to function, it can be kept public or private so we can control the access of data.
It does not have any proper way of hiding data, so it is less secure. OOP provides Data Hiding so provides more security.
Overloading is not possible. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading.
Examples of Procedure Oriented Programming are C, VB, FORTRAN, and Pascal. Example of Object-Oriented Programming are C++, JAVA, VB.NET, C#.NET.

Object-Oriented Programming Principles

  • Encapsulation
  • Data abstraction
  • Polymorphism
  • Inheritance
  • Dynamic binding
  • Message Passing
Encapsulation
Enter fullscreen mode Exit fullscreen mode

Wrapping data and functions together as a single unit is known as encapsulation. By default, data is not accessible to the outside world, and they are only accessible through the functions which are wrapped in a class. prevention of data direct access by the program is called data hiding or information hiding.

Data abstraction
Enter fullscreen mode Exit fullscreen mode

Abstraction refers to the act of representing essential features without including the background details or explanation. Classes use the concept of abstraction and are defined as a list of attributes such as size, weight, cost, and functions to operate on these attributes. They encapsulate all essential properties of the object that are to be created. The attributes are called data members as they hold data and the functions which operate on these data are called member functions.
Classes use the concept of data abstraction, so they are called abstract data types (ADT).

Polymorphism 
Enter fullscreen mode Exit fullscreen mode

Polymorphism comes from the Greek word “poly” and “morphism”. “poly” means many and “morphism” means form i.e., many forms. Polymorphism means the ability to take more than one form. For example, an operation has different behavior in different instances. The behavior depends upon the type of data used in the operation.
Different ways to achieve polymorphism are:
1) Function overloading
2) Operator overloading

Inheritance 
Enter fullscreen mode Exit fullscreen mode

Inheritance is the process by which one object can acquire the properties of another.
Inheritance is the most promising concept of OOP, which helps realize the goal of constructing software from reusable parts, rather than hand-coding every system from scratch. Inheritance not only supports reuse across systems but also directly facilitates extensibility within a system. Inheritance coupled with polymorphism and dynamic binding minimizes the amount of existing code to be modified while enhancing a system.

When the class child, inherits the class parent, the class child is referred to as a derived class (sub-class) and the class parent as a base class (superclass). In this case, the class child has two parts: a derived part and an incremental part.
The derived part is inherited from the class parent. The incremental part is the new code written specifically for the class child.

Dynamic binding:
Enter fullscreen mode Exit fullscreen mode

Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding (or late binding) means the code associated with a given procedure call is not known until the time of the call at run time.

Message passing:
Enter fullscreen mode Exit fullscreen mode

An object-oriented program consists of a set of objects that communicate with each other. Objects communicate with each other by sending and receiving information.

A message for an object is a request for the execution of a procedure and therefore invokes the function that is called for an object and generates a result.

Key Takeaways:

  • OOP: Object-Oriented Programming. A programming paradigm or approach is used to analyze and solve problems that are based on the representation of real-world objects in the system.
  • Class: one of the building blocks of Object-Oriented Programming that acts as a “blueprint” where the data and the actions of the objects are defined.
  • Instance: a concrete object that is created from the class “blueprint”.
  • Method: an “action” defined in the class that the instances of the class can perform. It is very similar to a function but closely related to instances such that instances can call methods and methods can act on the individual data of the instances.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.