Object-Oriented Programming for Newbies

Learning new programming skills can be quite overwhelming and intriguing at the same time. I bet you will start with learning the basic syntax which is a good practice. But how well will you answer these questions? "What is an Object-Oriented Program?" or explain Object-Oriented Program to anyone say a beginner or a potential employer or "What is the difference between Encapsulation and Abstraction?". cartoon-thinking-man-with-question-mark-think-bubble.jpg

Hmmm, got you there, right?

Alright, fasten your seatbelts while I take you on a tour on object-oriented programming for newbies. We will be looking at:

  • What is object-oriented programming(OOP)
  • Pillars of OOP
  • Difference between Encapsulation and Abstraction
  • Benefits of OOP
  • Object-Oriented Programming Languages(OOPL) and Examples

What is Object-Oriented Programming

What-is-OOP.jpg

Object-Oriented Programming is a type of computer programming model that organizes a group of related variables and functions into a unit. This unit is what we call an object.

This is quite a definition for a newbie. To be more realistic, think of your phone which you use to make calls and send emails. Here the phone is an object. The email and contact on the phone are just variables. To enable their functionality, you need to call on methods like verify() to verify an email or call() to call a contact.

Pillars of Object-Oriented Programming

Four Pillars of OOP.jpeg The four major pillars of OOP we will be discussing are:

  1. Encapsulation

    Think of a phone as a computer program. It has few logically different objects which communicate with each other according to the rules defined in programming the phone. Encapsulation is achieved when each object keeps its state private inside a class. Objects don't have direct access to this state. Instead, they can only call a list of public functions called methods. Still, on our imaginary phone, think of the contacts and the email address as variables. To make a call, you will have to call on the dial option to make a call. Here, dial() is a method that you call on from the contact to make a call.

  2. Abstraction

    In OOP models, programs are usually very large with different objects communicating in a designed way behind the scene. Abstraction helps in hiding internal implementation details, revealing only relevant operations in the program. abstraction.png A practical example of how abstraction works is a phone. When interacting with buttons on a phone, do you know what's going on inside the phone? Abstraction has played a relevant role in keeping those details behind the scene. This has made interaction with a phone easier and user friendly.

  3. Inheritance

    In OOP, objects tend to share logical ideas with themselves but are not entirely the same. Acquiring those similar properties is possible in OOP. Inheritance allows a class(child) to acquire the properties and behavior of another class(parent). The class(child) reuses the fields and methods of the class(parent) and can implement its unique part. It helps to reuse, customize, and enhance the existing code. It also helps to write code accurately and reduce the development time.

  4. Polymorphism

    A (child)class can have their own behavior and also have the ability to behave like their (parent)class in OOP. This is known as Polymorphism. Polymorphism gives a way to use a (child)class exactly like its (parent)class, not the other way round. This ensures there is no confusion with mixing types.

Difference between Encapsulation and Abstraction

A lot of people tend to mix up the concept of encapsulation and abstraction. This is no surprise because they are both used for hiding classes, objects, and variables but different purposes. There are some other worthy differences but this is a simple one.

  • In encapsulation, objects and variables are kept private. They can interact with other similar objects and variables through methods. The purpose of keeping their state private is to prevent outsiders from access it directly.

  • While abstraction is used for hiding classes and objects whose implementation is not needed to be known to the client. These classes, objects are important but they are of no relevance to the client.

Benefits of Object-Oriented Programming

The organization of an object-oriented program also makes the method beneficial to collaborative development, where projects are divided into groups. Other benefits include code reusability, scalability, efficiency, flexibility through polymorphism, effective problem solving, and security.

Types of Object-Oriented Programming Languages

An object-oriented programming language (OOPL) is a high-level programming language based on the object-oriented model. To perform object-oriented programming, one needs an object-oriented programming language. Here are types of OOPL:

  • Simula
  • Java
  • JavaScript
  • Python
  • C++
  • Visual Basic .NET
  • Ruby
  • Scala
  • PHP

I hope this tour helped. If you find any part of the article you disagree with, leave a comment.