Object-Oriented Programming: A Quick Overview

Share this

Object-oriented programming, also commonly known as OOP or OOPs is a programming style or paradigm in which we look at the problem or the software requirement with an object-oriented approach.

What do you understand by object-oriented programming?

The fundamental or core of OOP is classes and objects. The whole concept of OOP revolves around classes, objects, the way of their interaction, the ability to show the different forms of behavior, data binding, data hiding, etc.

What are classes & objects?

Classes and objects are basic building blocks of object-oriented programming. Classes can be inferred as a blueprint and objects are the instances of a class which are having properties and behavior which have been defined in the blueprint i.e. class.

What are the four pillars of OOPs?

There are four main pillars of OOPs as listed below:

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

Please check out the above links to understand more in detail. We will cover each of these OOPs building blocks very briefly in this post.

What is Encapsulation?

Encapsulation essentially means binding or encapsulating the data and behavior. It is the very fundamental step where the OOP starts to shape itself. It is fulfilled in two ways:

Data Binding

It is the process of binding data members and method members together because of which a self-sustainable instance of a class i.e. object can come into existence. A Java POJO or Java Beans class is the perfect example of data binding.

Data Hiding

Data hiding is another part of the encapsulation concept in which unwanted access to the data members of a class is restricted by using access specifiers like public, private, and protected. Making data members private in a bean class and allowing it to be accessed only through getter methods is an example of data hiding.

What is Abstraction and how is it implemented?

Abstraction basically means hiding unnecessary implementation details and showing only the required information to the users. For example, if we talk about web services, it is a perfect example of abstraction. The web service producer does not need to show the implementation details but just needs to expose the endpoints to which a consumer can interact and get the desired output. Here, a consumer is not concerned about the internal implementation details. A weather RESTful API is an example abstraction.

How do we achieve abstraction?

Abstraction is achieved by using abstract classes and interfaces. An interface helps in achieving 100% abstraction whereas an abstract class helps in achieving partial abstraction. Partial or full abstraction is implemented based on the requirement or the problem at hand.

What is Inheritance and how is it implemented?

Inheritance is one of the four basic concepts of OOPs. It mainly focuses on reusability. Inheritance is achieved by implementing a parent-child relationship between the classes. It is implemented in Java using the “extends” keyword. It allows sharing the resources i.e. data and method members among the parent and child classes.

Inheritance is of the following types –

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Hierarchical Inheritance
  4. Hybrid Inheritance
  5. Multiple Inheritance

Note: Multiple inheritances are not supported in Java because of its ambiguous nature and to avoid the Diamond Problem.

Check our other blog for detailed information on Inheritance

What is Polymorphism and how is it implemented?

The literal meaning of Polymorphism is “Poly” = many and “morph” = form. This OOPs feature allows member methods to be able to exist in different forms. Polymorphism is implemented in two ways –

Method Overloading / Compile-time polymorphism / Static/Early binding

As the name suggests, a method can be overloaded within the class. Method overloading means that more than one method with the same name but different method signatures can exist in a class. Method overloading with the same name and the same signature will give a compilation error because the compiler checks for the binding during compile time, hence called compile-time or static/early binding.

Method overriding / Runtime polymorphism / Dynamic binding

Method overriding helps in implementing various forms of methods by overriding their behavior in parent-to-child classes. Since it is unknown to the compiler which class will be invoked at the runtime, it is called run time polymorphism, as the classes are bound dynamically at the runtime. A method is overridden by using @Override annotation in java

With this, we come to the end of this quick overview. Stay tuned on this topic for more.

Feel free to share your thoughts on this topic in the comments section below 👇 We would be happy to hear and discuss the same 🙂

Share this

Leave a comment

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

2 thoughts on “Object-Oriented Programming: A Quick Overview”