Object-Oriented Programming

Table of contents

Automate your business at $5/day with Engati

REQUEST A DEMO
Switch to Engati: Smarter choice for WhatsApp Campaigns 🚀
TRY NOW
Object-Oriented Programming (OOP)

What is the meaning of Object-Oriented Programming (OOP)? 

Object-oriented programming (OOP) is a modeling system and one of the classifications of programming languages built on the concept of "objects" which can contain data and code. Where "data" denotes fields, attributes, or properties and "code" is referred to as the methods or procedures. 

Object-oriented programming is about modeling a system as a collection of objects, which each represent some particular aspect of the system. Objects contain both functions (or methods) and data. An object provides a public interface to other code that wants to use it, but it maintains its private internal state: which means that other parts of the system don't have to care about what is going on inside the object. Object-oriented programming is faster and easier to execute and provides a clear structure for the programs. 

OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug. Programming languages like C++, Java, Python, etc support object-oriented programming to a greater or lesser degree, combined with imperative, procedural programming. 


Source: Medium 


What are the concepts/ principles of Object-Oriented Programming? 

There are four main concepts/ principles of Object-oriented programming (OOP), known as Abstraction, Encapsulation, Inheritance, and Polymorphism.

Understand these 2 terms before starting the concepts: 


Class: A class is a collection of objects that defines a set of properties that is common to all objects of a particular type. It can also be called a blueprint for creating objects. A class entails class name, modifiers, and body. 
Object: An object is defined as an instance of a class and contains real-life entities. For instance, for a class called Animals, Its objects will be a cat, dog, elephant, etc. Each object has its own identity, attribute, and behavior. 

1. Abstraction

Is also known as Data Hiding, where we hide a portion of data and show only the relevant part to the final user. Abstraction helps isolate the impact of changes made to the code so that if something goes wrong, the change will only affect the implementation details of a class and not the outside code.

Let's take a real-life example to understand the concept better when we press our finger on a biometric device to open a gate or click on the press the biometric feature on our phone, it automatically opens the system/door. We understand and know the technology on the surface but might not know how it works inside or might not have an urge to understand how it works. Data Abstraction works similarly, as it shows or reflects only the relevant part and hides the less relevant data on purpose. 

In C++ data abstraction can be accomplished in 2 different ways- 

  • using class
  • using header file

2. Encapsulation

Encapsulation is the concept of wrapping together data & information in a single unit to save it from manipulation and external excess. The motive behind encapsulation is to hide and bind the data, functions, and logic into a single unit, the class, using access specifiers. 

By doing so, we can hide private details of a class from the outside world and only expose functionality that is important for interfacing with it.

Example:  (Source: ProCodeGuide )

“An encapsulated class "Employee" in which we have specified properties Name & Total Experience to be specified by User. Employee Id is generated internally in class and generation logic is not exposed to the user also user can only read Employee Id and cannot change it. Similarly, salary is also calculated internally in class, and the user can access employee salary by the GetSalary method”.


3. Inheritance

Under the Inheritance mechanism, a class inherits the features (fields and methods) of another class. As it's very important in Object-Oriented Programming to allow the reusability factor from the functionality perspective. 

  • Super Class: The class whose features are inherited is known as superclass (or a base class or a parent class).
  • Sub Class: The class that inherits the other class is known as a subclass (or a derived class, extended class, or child class). The subclass can add its fields and methods in addition to the superclass fields and methods.
  • Reusability: Using an existing set of codes while creating a new class. 

4. Polymorphism

It is considered one of the important features of Object-Oriented Programming. Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations. 


What are Object-Oriented Programming design patterns? 

A design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-Oriented Programming design patterns are divided into 3 categories; Behavioral Patterns, Creational Patterns, and Structural Design Patterns.
Following is the list of all the design patterns used in OOP.


Behavioural

Creational

Structural

Interpreter

Factory Method

Adaptor (class)

Template Method

Abstract Factory

Adaptor (object)

Chain of Responsibility

Builder

Bridge

Command

Prototype

Composite

Iterator

Singleton

Decorator

Mediator

 

Facade

Momento

 

Flyweight

Observer

 

Proxy

State

 

 

Strategy

 

 

Visitor

 

 


How does Procedural Oriented Programming differ from Object-Oriented Programming? 

Following are the important differences between Procedural Oriented Programming (POP) and Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP)

Procedural Oriented Programming (POP)

  • Object-oriented Programming is a programming language that uses classes and objects to create models based on the real-world environment. In OOPs it makes it easy to maintain and modify existing code as new objects are created inheriting characteristics from existing ones.
  • On the other hand, Procedural Oriented Programming is a programming language that follows a step-by-step approach to break down a task into a collection of variables and routines (or subroutines) through a sequence of instructions. Each step is carried out in order in a systematic manner so that a computer can understand what to do.
  • In OOPs concept of objects and classes is introduced and hence the program is divided into small chunks called objects which are instances of classes.
  • On the other hand, in the case of POP,  the main program is divided into small parts based on the functions and is treated as a separate program for the individual smaller programs.
  • In OOPs access modifiers are introduced namely as â~PrivateâTM (Private), â~publicâTM (Public), and âTM~ProtectedâTM (Protection).
  • No such modifiers are introduced in POP.
  • Due to abstraction in OOPs data hiding is possible and hence it is more secure than POP.
  • POP is less secure as compared to OOPs.
  • OOPs due to modularity in their programs is less complex and hence new data objects can be created easily from existing objects making object-oriented programs easy to modify
  • No simple process to add data in POP at least not without revising the whole program.


What are the examples of Object-Oriented Programming Languages?

  • JAVA
  • PYTHON
  • PHP
  • C++
  • PERL
  • LISP
  • COBOL
  • C#

What are the advantages of Object-Oriented Programming? 

Advantages of Object-Oriented Programming

1. Reusability

OOP allows us to use the existing codes through inheritance. We can easily acquire the existing functionality and improve on it without having to rewrite the code again.

2. Modularity

In OOP, it’s easy to modify or troubleshoot the program if a problem occurs or if we need to add a new feature or enhance the existing one. 

3. Flexibility

OOP helps us with flexible programming using the polymorphism feature. As polymorphism takes many forms and can work with many objects. It can save us from writing different functions for each object.

4. Maintainability

Maintaining code is easier as it is easy to add new classes, objects, etc without much restructuring or changes.

5. Data and Information Hiding

OOP aids us in data hiding and keeps the information safe from leaking. Only the data that is required for the functioning of the program are exposed to the user by hiding intrinsic or extra detail.

Close Icon
Request a Demo!
Get started on Engati with the help of a personalised demo.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
*only for sharing demo link on WhatsApp
Thanks for the information.
We will be shortly getting in touch with you.
Oops! something went wrong!
For any query reach out to us on contact@engati.com
Close Icon
Congratulations! Your demo is recorded.

Select an option on how Engati can help you.

I am looking for a conversational AI engagement solution for the web and other channels.

I would like for a conversational AI engagement solution for WhatsApp as the primary channel

I am an e-commerce store with Shopify. I am looking for a conversational AI engagement solution for my business

I am looking to partner with Engati to build conversational AI solutions for other businesses

continue
Finish
Close Icon
You're a step away from building your Al chatbot

How many customers do you expect to engage in a month?

Less Than 2000

2000-5000

More than 5000

Finish
Close Icon
Thanks for the information.

We will be shortly getting in touch with you.

Close Icon

Contact Us

Please fill in your details and we will contact you shortly.

This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
Thanks for the information.
We will be shortly getting in touch with you.
Oops! Looks like there is a problem.
Never mind, drop us a mail at contact@engati.com