Object Oriented Programming

By | February 9, 2020

Object-Oriented Programming, you must have heard of this term when we talk about a high-level programming language, to define any programming language we mention whether the programming language support Object-Orientation programming or not. If you’re a student of computer science you may encounter this question “What is OOPS?” in your exam, and even in tech interviews, the interviewer could ask you the same question. Often when someone asks us what is OOPS? in response we tell them the definition of class and object, which is incorrect, though class and objects are the core part of Object-Oriented programming, we cannot define OOPS with the definition of class and objects. Here in this article, we have provided an answer of What is Object-Oriented programming and how class & objects are related to it, we have also discussed the major properties of OOPS that a programming language should follow to be an Object-Oriented Programming Language.

What Is Object-Oriented Programming(OOPS)?

A simple definition of OOPS says “Object-Oriented Programming is a programming paradigm which uses the concepts of Objects” (A programming paradigm means an approach to solving a problem in a specific manner).

Let’s break the above definition of OOPS and understand it in a nutshell, An Object-Oriented Programming language is an approach to solve the real-world problems using the concept of objects, in Object-Orientation programming, we can create an Object which can hold data and functions (attributes and methods) so the operations of the functions could only be applied on that specific data.

Now, every High-Level programming language supports OOPS because it provides some concepts which are often used to solve real-world problems. The concept of OOPS also known its properties which includes topics like:

  • Class
  • Objects
  • Polymorphism
  • Inheritance
  • Encapsulation
  • Abstraction

Difference between Procedural Programming and Object-Oriented Programming:

In procedural programming we make functions and those function can apply on a data, whereas Object-oriented programming we create an object which contains both data (attributes) and function (methods) so the functions can be applied on specific data.

As compare to Procedural programming implementation of OOPS is a little complex but it helps to c complex algorithm.

Advantages and Disadvantages of OOPS

Advantages

  • With OOPS we can have a more modular structure approach in which we can hide the implementation of functions and data.
  • OOPS with its some properties introduce the principle of DRY “Don’t Repeat Yourself”, which promotes the concept of code reusability.
  • Program written using the OOPS concept can be easily maintained if we want to update some features of the program or want to add something new, for that we do not have to change the complete structure of the program.
  • Using OOPS, we can create high-quality programs with low-cost development
  • It provides more Productivity as compare to Procedural Programming Paradigm.

Disadvantages

  • Implementation of OOPS concepts is a little tricky as compared to procedural programming.
  • OOPS involves more lines of code to create a program, as compared to Procedural programming.
  • The execution of OOPS program is slower than procedural programming
  • It cannot be used to solve every kind of problem.

How Class and Objects are related to OOPS?

Before we tell you how class and object used along with OOPS let’s have a look at the definition of each one.

Class

A class is a blueprint which contains all the instruction related to an object, a class has no existence in the program until its object gets created. The class also determines all the properties of an object no matter how many objects of a class get created all of them will have the same properties.

Object

When we want to bring the class in existence we create an object of that class, we can say that an object is a soul of class, and there could be more than one object of a class. With the help of an object, we can access all the instruction of the class.

Class and Object Example using Python

class Human:

    def __init__(self):
        self.hands =2
        self.legs =2
        self.eyes =2
        self.fingers = 10

sam = Human()
will = Human()

Class and Objects are an important part of OOPS because with the help of these two concepts we implement all the other properties of OOPS in a programming language from Polymorphism to Encapsulation we can implement everything using class and objects.

Properties of Object-Oriented Programming language

To be an Object-Oriented programming language, that programming language should follow the properties of an OOPS which are:

  • Encapsulation
  • Abstraction
  • Polymorphism
  • Inheritance

1. Encapsulation

With Encapsulation we deal with wrapping the data and methods under a single unit or entity and class is the perfect example of implementing the concept of Encapsulation. With encapsulation, our approach is to bind the data and its properties using a single entity so the code cannot be manipulated by any outer factor.

Encapsulation also promotes the concept of data hiding if there are two classes one class cannot use the data of another class until the developer itself allow the accessibility explicitly.

2. Abstraction

Abstraction can be defined as the extension of the Encapsulation property, in Abstraction we deal with the hiding of important information and detail from the user. For example, when we create a program, to access its functionality we provide some buttons so the user can access the functionality of the program, without knowing the real code behind it. In abstraction, we try to hide the irrelevant details from the user so the user only communicates with the program output rather than program working.

3. Polymorphism

Polymorphism is a Greek word, which means “many shapes”, and as its name suggest polymorphism deal with the multiple shape or nature of an object, in OOPS polymorphism helps to differentiate between two objects having same nature or structure. For example, if we use the + operation between 2 integers it will perform the addition operation, but instead of using + operator between two integers if we use it between two strings it performs the concatenation operation.

Polymorphism itself bought two important concepts which are:

  • Method Overloading
  • Method Overriding

4. Inheritance

Inheritance is the most important property of OOPS; it is a property that brings the concept of code reusability in Object-Oriented programming languages. Using the concept of inheritance one class can inherit the public and protected properties of another class.

Using the concept of inheritance, you can use any module written by another developer so you do not need to write the complete code from scratch.

There are various types of Inheritance such as:

  • Single Inheritance
  • Multiple Inheritance
  • Multi-level Inheritance
  • Hybrid Inheritance

Summary

  • Object-Orientation is a programming paradigm that uses the concept of the object to solve any problem.
  • A programming paradigm is an approach to solve a problem in a specific manner.
  • Every high-level programming support object-oriented programming
  • A class is a blueprint of a solution.
  • An object is an entity which brings a class in existence
  • Polymorphism, Inheritance, Encapsulation, and Abstraction are the four major properties of Object-Oriented programming.

Conclusion

Whatever programming language you chose to learn in 2020 make sure that it supports Object-Oriented programming. As with Object-Oriented programming, we cannot solve every problem so keep in mind that do not completely depend on OOPS when writing code for your project.

If you like this article or have any suggestion related to the Object-Oriented programming, please let us know by commenting down below. Your feedback will be a valuable asset to us.

Leave a Reply

Your email address will not be published. Required fields are marked *