Object Oriented Programming (OOP) for dummies

Object Oriented Programming (OOP) for dummies

Starting to learn a programming language can be fascinating until you get stuck on a little problem that sounds so basic that you are wondering why you can't tackle it. Learning the basics and understanding how the programming language works cannot be overemphasized, it is very important. Let me walk you through understanding Object-oriented programming in the simplest terms.

In this article, you will learn:

  • What is OOP
  • Principles of OOP
  • Examples of Object oriented languages

Object Oriented Programming (OOP) is a computer programming model that revolves around the concept of an object. Everything is treated as an object that has unique attributes and behaviour. Now let’s look at the human being Ruth as an object, she has attributes like eyes, nose, hands etc. but this object also does some stuff like she can walk, run and eat. This method of programming aids flexibility, reusability of code and effective problem solving.

Now let’s dive in the Principles of OOP

images (1).jpg

  • Abstraction

You know how you don’t actually understand or know how the results of your random web search are displayed in your browser like what happens behind the scenes, that’s how the abstraction principle works. It hides the background(inner) implementation details revealing only what is relevant to the user.

  • Encapsulation

Think about your pizza, you know the pizza company do not want the delivery guy messing up your pizza, so they have to enclose it in a carton and package it very well. The encapsulation principle works similarly. The object keeps its data private inside a class so other objects do not interfere with this data. You don’t want your user messing up the internal data and making it invalid so you have to secure it.

  • Inheritance

I’m sure you have one or more traits from either of your parents eye color, body physique name it. Now with inheritance in OOP, you can create a child object from a parent object. The child can reuse all the attributes and behaviour of the parent and can also implement its own. This principle can help in managing large codebases.

  • Polymorphism

Polymorphism is derived from two greek words meaning many forms. In this principle, objects can take more than one form depending on the context. the new object can override the parent methods and cause itself to react to a message differently.

Now here are some examples of Object-oriented languages:

  • Python

  • PHP

  • Java

  • Ruby

  • Go

So as a Pythonista, I’d share a mnemonic i use to remember the principles of OOP: I Always Enjoy Python (IAEP) standing for Inheritance, Abstraction, Encapsulation and Polymorphism.

You can check the references for more information on OOP. Thanks for reading !

References

  1. freecodecamp.org/news/object-oriented-progr..

  2. dev.to/charanrajgolla/beginners-guide---obj..

  3. searchapparchitecture.techtarget.com/defini..