Labaran Adam

Fell in love with a dumb machine that does exactly what I instruct it to do, when and how. Hoping our relationship makes the world a better place. || SOFTWARE ENGINEER

Object Oriented Programming Concept

February 12, 2020

Before Object Oriented Programming we have procedural programming which has a lot of disadvantages such as the inability to reuse code throughout the program. As your program grows, you create a lot of functions. This creates so much interdependency between the functions you created. As you make a change to a function another function brakes. Object-Oriented Programming came in to solve this and a lot of problems for us. Knowing and mastering OOP is an essential skill a developer will need if he wants to build large and scalable software’s

What’s Object-Oriented Programming

Object-Oriented Programming is a way of programming which allows programmers to combine a group of related variables and function into a single unit. let take a glance at some basic Terms

Class

A class is like a blueprint or a template for creating objects. It provides the definition for an object. Let take a look at an example, before you build a house , you start by designing a plan for the house, you define the properties and behaviour of the house in the plan. Then you can use the plan to build different houses in a different location. In OOP the plan will be defined as a class

Object

Object can be defined as the instance or version of the class. Since you built your house at different locations. let say in location A we built a house with the same plan and in location B we also have a house built with the same plan. The houses in these various locations will be an instance of the class. In OOP an instance of a class is called an Object

Method

Method can be defined as the behaviour of the class, it tells what the class can do. Instantiation The creation of an instance of an object of a class is called ## Instantiation.

OOP’s Concepts

There are four Pillars of Object-Oriented Programming namely

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

Let try to understand each of them in the simplest way

Abstraction

Abstraction is a process of showing only the functionality of a system. In this case, the programmer hides all except the relevant feature about an object. This reduces complexity allowing you to picture systems as if you were actually manipulating it instead of the actual implementation. In abstraction how the object was created and what goes under the hood is not relevant to you.

Encapsulation

Encapsulation implies the idea of hiding the content of a class unless its necessary to be exposed. This prevents unauthorized parties from direct access to them. This prevents them from changing the state of the hidden data.

Inheritance

Inheritance is the process where one class acquires the properties and methods from another class known as the base or parent class. Using inheritance in a derived class, this allows us to reuse the code of existing superclasses or base class

Polymorphism

Polymorphism is the ability of an object to take on many forms. Let try to understand it by taking an example from an animal class. Let say we have a base class animal and derived classes dog, snake, and cat. Inside the base class, we have a method speak() which will output how the animals speak. all derived class will have their own version of speak. so the speak method inside the dog class will output ( dog barks ), the speak method inside the cat class will output ( cat mews ) and also the speak method inside the snake class will output (snake hiss ) The characteristic of being able to assign a different meaning or usage to the speak() method to each derived class is known as polymorphism Thank You

Share This Post