DEV Community

Jai
Jai

Posted on • Updated on

What is the objective of Object-Oriented Programming

When someone asks us what is OOPS, we start our explanation with pillars of OOPS like abstraction, polymorphism, encapsulation, and Inheritance. In this article, we will take a step back and understand Object-oriented first before covering its pillars.s.

According to Wiki, Object Oriented (of a programming language) using a methodology which enables a system to be modelled as a set of objects which can be controlled and manipulated in a modular manner.

alt text

Still analyzing? Well, let us understand this in simpler words. Object-oriented is a software design in which we can simply group data its data types and methods under a single package. Here we will be dealing with 2 main terms:

Class: Class is a blueprint of data and functions or methods. 
Objects: Objects are an instance of a class.

alt text

Here we can treat the home as a class which contains properties as people living in it and their actions as methods. Similar description in c# language can be represented as:

public class Home

{
        public string P1 { get; set; }
        public string P2 { get; set; }

        public void Paint()
        {

        }
}

Now home is a general class which can be used to represent families. For example, if someone wants to create Mr. C. V. Raman or Mr. Kalam house all they need is to create an object of this class and they can set the properties and invoke the method.

class Program
{
   static void Main(string[] args)
   {
      Home ramanHome = new Home();
      ramanHome.P1 = "Mr. C. V. Raman";
      ramanHome.P2 = "Mrs. Lokasundari Ammal";
      ramanHome.Paint(ramanHome.P1, ramanHome.P2);

      Home kalamHome = new Home();
      KalamHome.P1 = "Mr. A. P. J. Abdul Kalam";
      KalamHome.P2 = "None";
      KalamHome.Paint(ramanHome.P1, ramanHome.P2);
   }
}

Now if you notice we used the same Home class to describe 2 entities. Similarly to define other homes all we need is to create an instance of the home class and set the properties.

alt text

Hope the concept like Class and object are clear. Now, let us take a look at the pillars of OOPS, I'll just provide the basic definitions as there are enough articles available on the internet describing these pillars.

Abstraction: Abstraction is a process of hiding the implementation details and showing only functionality to the user.

Encapsulation: Wrapping of data and function in a single unit is called encapsulation. We hide the data from the outer world and doesn't allow the outer world to access them directly. This is known as data hiding.

Polymorphism: Polymorphism means the ability to take more than one form.

Inheritance: Inheritance is the process by which objects of one class acquire the properties of objects of another class.

Please do share your valuable feedback.

Discussion (0)