encapsulation vs abstraction real world example

前端 未结 17 2205
闹比i
闹比i 2020-12-12 10:59

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

17条回答
  •  孤城傲影
    2020-12-12 12:01

    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.

提交回复
热议问题