Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

encapsulation vs abstraction real world example

For an example of encapsulation i can think of the interaction between a user and a mobile phone. The user does not need to know the internal working of the mobile phone to operate, so this is called abstraction. But where does encapsulation fit in to this example? Could someone please shed some light on this?

like image 741
crowso Avatar asked Aug 22 '12 12:08

crowso


People also ask

What is real life example of encapsulation?

School bag is one of the most real examples of Encapsulation. School bag can keep our books, pens, etc. Realtime Example 2: When you log into your email accounts such as Gmail, Yahoo Mail, or Rediff mail, there is a lot of internal processes taking place in the backend and you have no control over it.

What is the real life example of abstraction?

Abstraction in the real worldMaking coffee with a coffee machine is a good example of abstraction. You need to know how to use your coffee machine to make coffee. You need to provide water and coffee beans, switch it on and select the kind of coffee you want to get.

What is the difference between encapsulation and abstraction explain with a real time example?

Abstraction focuses on outside viewing, for example, shifting the car, while Encapsulation focuses on internal working or inner viewing. Abstraction is supported in Java with the interface and the abstract class, and Encapsulation is supported using, e.g. public, private and secure access modification systems.

What is the difference between encapsulation and abstraction?

Abstraction is the method of hiding the unwanted information. Whereas encapsulation is a method to hide the data in a single entity or unit along with a method to protect information from outside. 4.


2 Answers

Encapsulation is a way to achieve "information hiding" so, following your example, you don't "need to know the internal working of the mobile phone to operate" with it. You have an interface to use the device behaviour without knowing implementation details.

Abstraction on the other side, can be explained as the capability to use the same interface for different objects. Different implementations of the same interface can exist. Details are hidden by encapsulation.

like image 138
davioooh Avatar answered Oct 04 '22 19:10

davioooh


Abstraction : you'll never buy a "device", but always buy something more specific : iPhone, GSII, Nokia 3310... Here, iPhone, GSII and N3310 are concrete things, device is abstract.

Encapsulation : you've got several devices, all of them have got a USB port. You don't know what kind of printed circuit there's back, you just have to know you'll be able to plug a USB cable into it.

Abstraction is a concept, which is allowed by encapsulation. My example wasn't the best one (there's no real link between the two blocks).

You can do encapsulation without using abstraction, but if you wanna use some abstraction in your projects, you'll need encapsulation.

like image 22
zessx Avatar answered Oct 04 '22 19:10

zessx