Basic Concepts of OOP #1























Today, in this post we are going to discuss about some basic concepts of OOPS. Now, let's get started!!

The OOP approach is based on certain concepts that help in attain its goal of overcoming the drawbacks of conventional programming approaches. These general concepts
of OOP are given below :

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

Let us understand each of them one by one.

1. Data Abstraction - Abstraction is the concept of simplifying a real world concept into its essential elements. Abstraction refers to the act of representing essential features without including the background details or explainations. 

To understand this, let us take an example. You are driving a car . You only know the essential features to drive a car e.g., gear handling, steering handling, use of clutch etc etc. But while driving do you get into internal details of car like wiring, motor working etc. ? You just change the gears or apply brakes etc. What is happening inside is hidden from you. This is abstraction where you only know the essential things to drive a car without including the background details or explainations. Take another example of "switch board" . You only press the switches according to your requirement without knowing what's happening inside.

2. Data Encapsulation - Encapsulation is the most fundamental concept of OOP . It is the way of combing both data and the functions that operate on that data under a single unit. or in other words "The wrapping up of data and operations / functions (that operate on the data) into a single unit (called class) is known as Encapsulation."

The only way to access the data is provided by the functions (that are combined along with data). These functions are called member functions. The data cannot be accessed directly. If you want to read a data item in an object (an instance of the class), you call a member function in the object. It will read the item and return the value to you. You can't access the data directly, the data is hidden so it is safe from accidental alterations. Data and its functions are said to be encapsulated into a single entity.

Now, let us take an real world example, suppose in a big company, there are so many departments, Sales, Accounts, Payroll, Purchase, Production etc. Each department has its own personne! that maintain its data. Suppose an employee in the production department wants to know how much raw has been purchased for the next month. The production dept employee would not be allowed to himself go through the purchase dept. data files. Rather he'll have to issue a memo to 'purchase' requesting for the required information. Then some employee of the 'purchase' dept. will go through the purchase data files and send the reply with the asked information. This practice ensures that data is accessed accurately and that it is not corrupted by inept outsiders. Therefore, we can say here 'Department data and department employees are encapsulated into a single entity, the department' . In the same way objects provide an approach to program organization while helping to maintain the integrity of the program data. Since the classes use the concept of data abstraction, they are known as Abstract Data Types (ADT) . 'Data types' because these can be used to create objects of its own type.

Note : Encapsulation is a way to implement data abstraction. Encapsulation hides the details of the implementaion of an object. Abstraction and Encapsulation are complementary concepts : abstraction focusses upon the observable behaviour of an object, whereas encapsulation focuses upon the implementation that gives rise to its behaviour. Encapsulation is most often achieved through information hiding.

Now, thats all for today , in our next session we understan few other OOPS concepts like inheritance, polymorphism and modularity. STAY TUNNED!!
SHARE

Raunak Hajela

Hi. I’m CEO/Founder of Kodestat. I’m Student, Geek, Web Designer, Developer, Blog Enthusiast and Player. Inspired to make things looks better. I like playing with codes plus I am marvel fan :-P You can check my design portfolio here. For consulation fell free to drop an email at raunakhajela@gmail.com.

  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment