Thursday, December 4, 2014

A PIE

Again in mathematics with that 22/7 ?
No, its not Pi, its PIE.

A PIE stands for

  1. Abstraction
  2. Polymorphism
  3. Inheritance
  4. Encapsulation
Let me tell you about these in a little deeper,
  • Abstraction - In our practical life, we experience this almost with everything. We use our cell phone, but don't know how it works, you are reading this post with merely a zero knowledge (unless you are from networking background) of what goes underneath and there are uncountable examples we can see of abstraction. Same is the concept of OOP. Objects interact with each other using their exposed methods but never know, what all is going out of there visit. For example, if object A is interacting with object B via some methods, A will never get to know, what B is doing out of its sight and vice-versa. This is known as Abstraction in OOP.
  • Polymorphism - Polymorphism means an object can be seen in different forms. This is basically a biological term which means that an organism or species can have many different forms or stages. In OOP also, we can have an objects and methods in different forms.
  • Inheritance - This is a very powerful feature of OOP. 

    Inheritance provides two benefits, first it determines an 'IS A' relationship or Generalization. Which means that if two or more object has the same characteristics, then it should be extracted in a general verion of class. And the special characteristics can be defined in the more special version of class. Check the following,
    A male employee is a man who is a human being who is an animal which is a living object. So, male employee has five forms employee, man, human being, animal and living object.Note carefully, a living object has some general characteristics and an animal has some special characteristics, and in every form it is possible. The below picture depicts this,
Second benefit of Inheritance is code reusability. Imagine, you have a plate of fruit salad in front of you, would you like to take that one or will you again go to kitchen, follow the recipe and make another one ? I think, the first choice is more suitable to you (for me as well). If I have something with me, then why do I bother to make that again ? Yes, this is the concept of Inheritance. If you have written a piece of code, reuse it. Through Inheritance, you can do such in OOP.

  • Encapsulation - Encapsulation is built on the concept data hiding. It basically provides following two objectives
  1. Builds the data and the function in a single unit
  2. Restricts access of object components 
           Main benefit of Encapsulation is to modify our implementation without breaking other's.

Lot's of features and it will be even more interesting, when we'll implement all these in our code...

So, Java is Object Oriented ?
Yes, Java is object oriented. We work with objects and interaction of different object is done via methods. Java supports the major features of OOP, A-PIE.



Prev     Next
Palash Kanti Kundu

No comments:

Post a Comment