Object Oriented Programming (OOP)

Object Oriented Programming OOP

Programming has immensely evolved over the years. Developers around the world have always learned procedural programming as a part of their basic training. This method is quite simple as it separates a program into a set of functions. Each function defines how a certain action will be executed. The functions act on a set of data to produce certain results. However, as the complexity of a program increases, procedural programming experiences a spaghetti code. This is when a copy pasting code for similar functions repeatedly causes the previous line to break. This is where Object Oriented Programming comes into play.

What is Object Oriented Programming?

OOP or Object Oriented Programming was introduced to solve the problem of ‘spaghetti code’. It works by grouping related variables and functions into a single unit called an object. The function is called the method while the variable or data is known as a property. There are four principles of OOP namely; encapsulation, abstraction, inheritance and polymorphism. In this article we will explain these principles using simple terms to make things easier for anyone trying to understand this programming type.

a. Encapsulation

This principle refers to the state where related objects that have been grouped together are kept in a private state. This means that other objects don’t have direct access to them unless explicitly allowed by the programmer. As a result, the encapsulated objects remain independent of the other elements, also known as methods.

b. Abstraction

It can be called an extension of encapsulation. To understand the practicality of abstraction, consider a Television set or gaming console. You hit a button on the appliance and it performs the desired function. However, there is a lot of complex interactions happening on the inside that are hidden from you. This is exactly what happens in encapsulation. Certain complex functions are hidden from normal view. This has a few advantages:

  1. It allows the program to have a simpler interface,
  2. It reduces the impact that changes in code have on the code. Since there is no code on the outside the visible influence is negligible,

c. Inheritance

This principle saves programmers the practice of writing similar functions for different elements again and again. For instance, in an HTML code there are several elements that have common properties and methods. Instead of defining them for each element separately, inheritance allows you to write them once and have other elements share them. This makes complex programming much simpler.

d. Polymorphism

This is a Greek word that means many forms or shapes. Polymorphism in OOP is a technique that allows programmers to define more than one way to do something by either changing the way it is performed or by modifying the parts used, in which it is done.

Object Oriented Programming is something that is frequently quizzed during job interviews because it helps the employer understand the technical knowledge and skill set of an individual. It is a simple technique depending on whether you’ve understood the basic functions or not.

 

If you are interested in learning more about Object Oriented Programming OOP send us an email to info@outcoding.com or visit our Contact Us page.