Oops!! What is OOPS ?

Anusha Patil
Catalysts Reachout
Published in
5 min readAug 29, 2022

Object-oriented programming (OOP) : is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.

It is used to structure a software program into simple, reusable pieces of code blueprints (usually called classes), which are used to create individual instances of objects. There are many object-oriented programming languages including JavaScript, C++, Java, and Python.

Why OOPs are Popular in Comparison to Other Types of Programming Principles?

Object-Oriented Programming Principles is the most popular amongst others because it relates to real-life objects. Every operation that is going to be functional is considered in terms of classes and objects. That provides a better programming style because you need not write code that needs to run anytime. Instead, you can create classes defining the functionality and call that function by creating an object of that.

Other than these, it also provides principles like inheritance, that increase the code reusability and help in applying updates very easily. And Abstraction, Encapsulation helps in enhancing the security of the data.

Languages that support Object-Oriented Programming are — C++, Java, JavaScript, C#, PHP, etc.
And Languages that are completely Object-Oriented Programming or Pure Object-Oriented are — python, Ruby, Scala, etc.

Building block of OOP

  • Object : Any entity that has state and behavior is known as an object. example- chair, pen, table, keyboard, bike etc. It can be physical and logical.
  • Class : A class can be stated as the blueprint of the object. This states what an object can do. It contains all the features, attributes, and behavior of what the model can do. We can say that class contains the definition of the object.
    example- Car color, engine type, etc.
  • Methods : Methods are the attributes of the class which are defined for the specified behavior of the object. It can also modify the state of the class.
    example-Method to drive a car, It changes the state of the car from parking state to running state.
  • Instances : It is the members of the class who holds some values related to the objects of the class.

Principles of Object-Oriented Programming

  1. Encapsulation
  2. Abstraction
  3. Inheritance
  4. Polymorphism

1.Encapsulation

Encapsulation can be defined as the binding of data and attributes or methods and data members in a single unit.

This mechanism keeps both data and functions safe from outside interference and misuse.

The advantage of encapsulated code is that user knows how to access it, there is no need of implementation details.

2.Abstraction

Abstraction can be defined as hiding internal implementation and showing only the required features or set of services that are offered.

3.Inheritance

When one object acquires all the properties and behaviors of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.

Single inheritance is defined as the inheritance in which a derived class is inherited from the only one base class.

where A is base class and B is derived class.

Multiple inheritance is the process of deriving a new class that inherits the attributes from two or more classes.

Multilevel inheritance is a process of deriving a class from another derived class.

Hierarchical inheritance is defined as the process of deriving more than one class from a base class.

Hybrid inheritance is a combination of more than one type of inheritance.

4.Polymorphism

Polymorphism means the ability to take more than one from. Polymorphism is one of the crucial features of the object-oriented programming.

Polymorphism allows the same method to execute different behaviors in two ways: method overriding and method overloading.

Method Overriding : Runtime polymorphism uses method overriding. In method overriding, a child class can provide a different implementation than its parent class.

Method Overloading : Compile Time polymorphism uses method overloading. Methods or functions may have the same name, but a different number of parameters passed into the method call. Different results may occur depending on the number of parameters passed in.

Constructors

Constructor is a special member function of a class which initializes itself when an object of class is created.

It is special function because its name is same as the class name.

The task of the constructor is to initializes the object of the class. It is called constructor because it constructor the value of data members.

Destructors

Destructor is use to destroy the object that have been created by a Constructor.

Like a constructor, the destructor is a member function whose name as the same as class name but is preceded by a tiled ().

A Destructor never takes any argument and it does not return any value. It is invoked implicitly by the compiler while exit from the program.

Actually destructor clear or clean memory storage i.e. it Works as a garbage collector. It is good programming practice to declare destructor to release memory space for future use.

Conclusion

Object Oriented programming requires thinking about the structure of the program and planning at the beginning of coding.

Implementing OOP allows for better data structures and reusability, saving time in the long run.

If you’d like to take a deep dive into OOP, Educative has courses for OOP in:

  • C++
  • Java
  • JavaScript
  • Python
  • C#

Thank you for reading , for more do follow !!

--

--