blog

Home / DeveloperSection / Blogs / Abstraction and Encapsulation

Abstraction and Encapsulation

Anchal Kesharwani2779 12-Aug-2014

In this blog, I’m explaining the abstraction and encapsulation.

In the Object oriented programming’s, Abstraction is one of the principle of object oriented programming.  Abstraction is the process of separating ideas from specific instances of those ideas at work. Abstraction means to show only the necessary details to the client of the object. For example, take a look at your mouse. Is it wireless? What kind of sensor does it have? How many buttons? Is it ergonomic? How big is it? The answers to all of these questions can precisely describe your mouse, but regardless of what the answers are, it's still a mouse, because it's a pointing device with buttons. That's all it takes to be a mouse. "Silver Logitech MX518" is a concrete, specific item, and "mouse" is an abstraction of that. An important thing to think about is that there's no such concrete object as a "mouse", it's just an idea. The mouse on your desk is always something more specific - it's an Apple Magic Mouse or a Dell Optical Mouse or a Microsoft IntelliMouse - "mouse" is just an abstract concept. Let us take the example of our laptop Keyboard itself, here we have a number of Keys, each performing some function dependent on the value given. Now all keys have a certain value that is accepted by the CPU when you press it. So we create a common object called Key with methods. This is abstraction show only the details which matter to the user.

Encapsulation is the term of Object Oriented Programming concept. Encapsulation like a capsule (medicine tablet) which hides medicine inside it. The wrapping up of attributes and behaviors into a single unit entity is called as encapsulation. Class is the best example of encapsulation. In Encapsulation increase the accessibility level of protection. Now if we consider a laptop, as an end user I have access only to some features of the system. So I could use the mouse to move the cursor, or the keyboard for typing text, but I would not have access to the internal components of the laptop. Again the keyboard in turn is bound internally to a set of methods that operate in response to a user action or an event.


Updated 18-Sep-2014

Leave Comment

Comments

Liked By