Tuesday, 23 August 2016

Basic Concepts of OOPs


The general concepts of OOP are given below:

1. Data Abstraction
2. Data Encapsulation
3. Modularity
4. Inheritance
5. Polymorphism



Data Abstraction

Abstraction is just representing the essential features with hiding the background details.
To understand it better, let's take an example, e.g., you are using a calculator and doing the sum by pressing the keys. Now you know every function of the key but you are not able to see what's going inside the calculator to do that simple sum. This is what we call Abstraction.


Encapsulation

The wrapping of the data and functions into a single unit is Encapsulation.
Just like you can see the above image, the capsule can be consider as a class which contains both the data and the procedures or functions into a single thing. 
Encapsulation is most often achieved through information hiding, which is the process of hiding all the secrets of an object that do not contribute to its essential features.

Modularity

Partitiong a program into individual components is called modularity i. e. it reduces the complexity and creates a number of well defined, documented boundaries within the program.
For example consider your computer. It consists of Monitor, Keyboard, Mouse, CPU, speakers, etc. These devices are complete units in themselves but yet are sub part of  your System.

Inheritance

The property of one class to inherit the properties of another class is called inheritance. Just like you own some of the features form your parents and have some of your own. Inheritance is needed many times during a program like when you need some attributes like the previous class you made. You are not gong to add those variables again because you need those variables+new variables. At that time inheritance comes handful. 

Polymorphism

Let's understand this with a simple example. Suppose you have three functions named circle, triangle and square. Now if I pass the comment that I want the area and run these functions, then they will give me the area but in their own way because all have different behaviors. Now the important part, when the message passed every function executed the code but in their own way. 

For Understanding More:

  

No comments:

Post a Comment