Search code examples
oopprogramming-languages

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?


Solution

  • 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 (i.e. devices, mobile phones). Different implementations of the same interface can exist. Details are hidden by encapsulation.