Object-Oriented Programming (OOP)
By: Rushi A Ranade
Tags: Programming, Quick Looks, Object Oriented

So what is Object-Oriented Programming?

Object-Oriented Programming, abbreviated as OOP, is a computer programming model that arranges software design around data, or objects, rather than functions and logic, systematically.

An object can be defined as a data field with unique attributes and behavior. It contains properties and methods. Let’s take an example; in a library management system, a book can be the object.

Object BOOK

It can have properties like ISBN, Title, Author and Year; and methods like inserting a book, updating a book, deleting or retrieving a book and so on.

Now let’s move on to the four pillars of Object-oriented Programming.

4 Pillars of OOP

Image taken from vivaxsolutions.com

As you can see the four pillars of OOP are:

Inheritance

Abstraction

Encapsulation

Polymorphism

1. INHERITANCE

geeksforgeeks.org

In inheritance there is one class/object subclasses another one. The object/class that is derived from the main class can be called the derived class while the main class can be called the base class.

Note: The term class can be used for the term object.

Let’s take an example, from the Book Object itself. Now all books will have to have an ISBN, a Title, an Author and a publication year. Some books may have an illustrator, some may not. Some books may have a co-author, some may not and some books may have ban on selling in some countries. If you form each book separately then it would look like this.

But if you take all the properties and put that in a base class…

…and make the books subclass the base class and add only the extra properties to the books. This is called inheritance.

2. ABSTRACTION

Abstraction is another vital practice in Object-Oriented Programming. Abstraction is used to show only the required attributes and hide unnecessary details of an object from the user. For example, you are logging into Google; you enter your Email ID and Password and click login. After you click login, how the data is sent to the Google servers, how it is checked, encrypted and all that is hidden from you, since you don’t need to know that information. All that you know is whether the login was successful or unsuccessful.

Login

3. ENCAPSULATION

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding. For example, a user’s name. If you use encapsulation on a user’s name, the person running the program can’t just hit user.name to get the name. He will have to use functions like getName() or showName() to see the user’s name.

3.1 ENCAPSULATION V/S ABSTRACTION

Source: Quora.com

4. POLYMORPHISM

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic.

Source: AskPython

4.1 POLYMORPHISM V/S INHERITENCE

Source: pediaa.com

This was a quick look at Object-Oriented Programming. Hope you liked it!