Fundamentals of OOPS

Ateev Duggal
4 min readJul 26, 2021

--

OOPS stands for Object-Oriented Programming System

It is a type of programming system that works on objects rather than the function which made the whole process a lot easier and consumes less space due to its reusability.

There are some basic terminology that one should know about moving forward in this concept -

What is an object?

The object is just a real-world entity with behaviors and attributes through which users can interact. We can also say that it is just an instance of a class.

What is a class?

A class is just a blueprint that contains some values and functions which are transferred to the object automatically upon its creation.

OOPS have many advantages but, there are some disadvantages too. We will discuss them in the next sections-

Advantages of OOPS

There are several advantages of using OOPS. Some of the main ones are-

  1. It makes reading, understanding, and maintaining code much easier than when it was written with functions. Thus reducing maintaining cost.
  2. Because of this solving problems becomes easy. No matter the difficulty, problems can be easily solved.
  3. It works on the principle of DRY — Don’t Repeat Yourselves as once an object has been made we can use it as many times as wanted, thus saving a lot of time and effort.
  4. It hides the codes which are not necessary with the help of data abstraction.

Disadvantages of OOPS

  1. It is not used when dealing with small problems as it is more suited for a complex or bigger problem.
  2. There is a sudden increase in problem-solving time.
  3. It requires proper planning and execution as a mistake can cost him very much.
  4. Since it requires proper planning and has to be built from the bottom, its execution rate is affected deeply as its processing speed is much lower than the procedural-based programs.

Pillars of OOPS

There are mainly four pillars on which this model stands

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

Polymorphism

A process in which any piece of data or object acts differently in different situations is called polymorphism.

It is a combination of two words poly and morphs which means the ability to take different shapes.

Let’s take an example — a human can be a child of their parents and at the same time be the parent of his children, can be an employee of a company, and can be the employer for those working under him.

It is mainly of two types -

  1. Compile Time Polymorphism
  2. Run Time Polymorphism

Compile Time Polymorphism

It is also called static polymorphism and only occurs at the compile time.

It is mainly of two types but can vary with the language

  1. Function overloading
  2. Operator overloading

Run Time Polymorphism

As its name specifies, a process that occurs at the run time. It is also known as dynamic polymorphism.

Inheritance

As the name suggests, the ability to have some or all properties from other classes(parent). It is the main reason why the reuse of code is possible in OOPS.

A perfect example will be a human child that inherits some of its parents’ ability in its DNA.

There are five types of inheritance-

  1. Single Inheritance
  2. Multiple Inheritance
  3. Multi-Layer Inheritance
  4. Hierarchical Inheritance
  5. Hybrid Inheritance

Single Inheritance

In this inheritance of the properties of a class(parent) are only given to only one other class(child).

Multiple Inheritance

In this type of inheritance, the properties a class (child) inherited are from multiple classes (parent).

Note — it is not permitted in java language.

Multi-layer Inheritance

In this type of inheritance, properties from one class(parent) are inherited by another class(child) are further inherited by another class.

It can also be explained as a type of inheritance that has more than one parent class but at different levels, as shown in the diagram.

Hierarchical Inheritance

In this type of inheritance, a parent class has more than one child class.

For example — when twins are reborn, they inherit some of the properties of their parents.

Hybrid Inheritance

A type of inheritance that is made of a combination of two types of inheritances is called a hybrid inheritance.

Limitations of Inheritance

  1. Requires more time to execute a program as it has to navigate different classes at different times.
  2. The parent and the child class have a are very tight bond which means that if any modifications have to be made in the program both parent and child class have to be modified accordingly
  3. It is very complex as already told before the parent and the child classes are tightly bound together, thus if not handled carefully may lead to some unexpected errors, and due to its complexity, finding the error may become the most difficult part.

Abstraction

It is one of the main reasons that OOPS is so popular as it hides the unnecessary part from the ones that do not need that.

For example — a mobile phone has many features like a camera, recorder, etc, but the user has no intention of knowing how they were made he just has to know how to use it or how it can solve my problem. Here the process of making such things that are not required by the user is hidden with the help of data abstraction.

Encapsulation

It is a process in which all the necessary data are bound together and presented to the user in such a way that he cannot do anything other than using those functions and cannot use the rest of the data until and unless given permission to invoke the hidden data and this has no effect on its other function that it is performing by default.

It is a type of abstraction as it hides all the unnecessary stuff from the user by not allowing him access to it.

--

--

Ateev Duggal

I am a front-end developer from India with over one year of experience in freelancing with skills like Git, HTML5, CSS3, Bootstrap 4&5, and React.