Sunday, 29 January 2017

RELATING OOP CONCEPTS TO REAL WORLD



Today we have many Object Oriented Programming Languages that use Object Oriented Programming concepts for their existence .Now we are going to see how these Object Oriented Programming concepts can be related to our real world.

There are five important concepts to be discussed here,
       1)Class
       2)Object
       3)Inheritance
       4)Data Abstraction
       5) Data Encapsulation
       6)Polymorphism
 Lets look at one by one..

CLASS and OBJECT:

The primary question that arises is What is class? How to Identify it ? The same questions are applicable even in case of object.Here,you can get a Rule of Thumb.
We can talk about class and object together because one becomes useless without the other.
Class is technically called as logical entity or model for creating objects.
Similarly, Object is known as real world entity or an instance of class.

Logical entity vs Real world entity 

Let us consider the following simple case.
I have my pet dog.Its  name is  Blacky. Now,what becomes my class and object??To find an answer for this,we need to answer two questions.Does really dog exist?The simple answer for this question is No.Because dog doesn't exist in the real world.I cannot see a dog (Even you too..).What about blacky ??It is an object !!! because it exists in the real world,and has all the characteristics of dog.
For example,If Male is a class then Mr.John is an object.(Male doesn't exist in the world,john exist ).



Conclusion:
Objects are the real world entities that represents class.


INHERITANCE:

Technically Inheritance is the process of acquiring the properties of the base class (parent class) by the derived class(child class).

Real World Scenario:

We can  easily relate Inheritance to our real world as the name itself has everything to know.The property owned by a parent will be inherited by the child.In addition to that ,child can have his own property.
In the same way if two classes are inherited,the instance of the child class(object) can access its data members and member function as well as its parent class data members and member functions.

ABSTRACTION:

Abstraction is presenting the relevant information to the user (hiding irrelevant information).

Real World Scenario:

If you want to log in into your google account,you will need to provide only your username and password.
if your password is correct.cheers!!! you are redirected to your mail box., if not,you get an appropriate message.But,this is not exactly the only thing that is happening.There are lot many things happen unknowingly  at the back end ,like how we are establishing connection to the gmail server,how the server is able to find whether the username and password are correct , how it is redirecting us to our account etc,which we really do not bother about.
This process of hiding  irrelevant data from the user is called abstraction.

ENCAPSULATION:

It is the process of combining data members and member functions into a single unit called class.

Real World Scenario:

In encapsulation data is not accessed directly.So,we implement encapsulation by defining access modifiers.
So, let us talk about defining access to  data members and member functions in a general scenario
let us assume that you have a car and an Internet servicing bank account.If your neighbour ask your car for a ride,what do you say?(probably yes ).But when your neighbour ask your sensitive bank details ,what do you say ?(probably No).
here we are defining the access to data members.Which is nothing but encapsulation.
We implement encapsulation in programming with access modifiers like public,private,default and protected.

POLYMORPHISM:

Polymorphism is nothing but ability to exist in more than one form.

Real World Scenario:

The best example for polymorphism is Milk.It has the ability to exist in more than one form as cheese,curd,ghee etc,In java we implement polymorphism by method overloading and method overriding.








1 comment:

  1. This is really great and derailed answer. Thanks whovever wrote this.

    ReplyDelete