Friday, 2 December 2016

OOP (OBJECT ORIENTED PROGRAMMIMG) CONCEPTS

Hello friends,

Today I am going to discuss about the most used programming paradigm i.e Object Oriented Programming (OOP).

There are basically two types of programming paradigms:

1) Procedure Oriented Programming
2) Object Oriented Programming

As this post is regarding OOP concepts, I will not discuss more about the procedure oriented programming, so below is just a simple comparison between both of theme.

Procedure Oriented Programming VS  Object Oriented Programming

Fig. OOP V/S PROCEDURAL PROGRAMMING

Now lets move on to the basic OOP concepts. But before that lets know about classes and objects.

What is a Class and Object..???

A class is used in object-oriented programming to describe one or more objects. It serves as a template for creating, or instantiating, specific objects within a program.

In short we can say that a Class is a blueprint for object creation. Class has no meaning if we don't have its' object.

To understand it better, lets take an example from our real life scenario.
Suppose an architect has to build a house for one of his clients. What will he do first is, he will create a blue print of the plan. Once he finalises all things ,like number of rooms, area for per room, terrace section, garden etc. the workers will start executing  the same plan in reality. It means the plan is blue print and the house which is going to be build is the object of that blue print. Unless and until workers build the house , that plan has no meaning. Again the architect can use the same plan to construct number of houses .

So in short, the plan is a Class and the house is an object of that Class.

Fig. CLASSES AND OBJECT IN REAL WORLD

The book definitions for class and object are :

Class: A class can be defined as a template/blueprint that describes the behavior/state that the object of its type support.

Object : Object is an instance of a class.

Now lets see the most important OOP concepts

1) Abstraction: 


Abstraction can be defined as the way of presenting necessary things by hiding unnecessary things.

For example consider a mobile phone. As a End user we have been provided a user interface like back button, app icons to launch app, call button,valume keys etc. We just press one of these to perform certain task. Lets say we want to make a call, we will just select a contact and press call button. This will do our job of calling someone. But we don't know how exactly the call is connected to the other person, how the data is transmitted etc. So these are the unnecessary informations from the user perspective and thats why these are hidden.







                                       

                                                             Fig. ABSTRACTION



Another example is restaurant. When we go to restaurant we are given a menu card. We order something from the menu card and we are served with the dishes.
Here the dish is the necessary thing that the customer is interested in. The cooking procedure of the dish is not necessary for the customer. So its the abstraction.


                          

Fig. ABSTRACTION

2) Inheritance: 

Inheritance means acquiring properties of parent class. The derived class has all the properties of base class plus its own properties.

For example , lets say in a Company there are employees with different roles such as Marketing Executive, Developer, Cashier etc. They all are employees but in addition to that they have some specific roles which they have to perform . So here the employee is the base class and the Marketing Executive, Developer, Cashier etc are the derived classes .


Fig. INHERITANCE

3) Polymorphism: 

Polymorphism is the ability to take more than one form.

For example Consider a human being. Every human being has some roles to play. If its a male then he may be a son, husband, a father, an employee. If its female then she may be a daughter, a sister, a wife,a mother, an employee. So its the ability of a human being to take more than one role, and thats what we call Polymorphism in programming terminology.

Another example in terms of programming is addition operator. The + operator can be used for adding numbers and same operator can be used to concate two strings.


Fig. POLYMORPHISM

4) Encapsulation: 

It means wrapping up of data into single entity (class).

Example: We all have taken some kind of capsule at least once in a life. This capsule is nothing but the encapsulation. That capsule may have various chemicals but they all are wrapped together in a single entity called Capsule.

Another example is any car. The car has many parts like wheels,stearing, seats etc. but they all are bounded together to make a single car.

            

Fig. ENCAPSULATION





Share:

0 comments:

Post a Comment