encapsulation vs abstraction real world example

前端 未结 17 2189
闹比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 11:52

    Encapsulation is hiding information.

    Abstraction is hiding the functionality details.

    Encapsulation is performed by constructing the class. Abstraction is achieved by creating either Abstract Classes or Interfaces on top of your class.

    In the example given in the question, we are using the class for its functionality and we don't care about how the device achieves that. So we can say the details of the phone are "abstracted" from us.

    Encapsulation is hiding WHAT THE PHONE USES to achieve whatever it does; Abstraction is hiding HOW IT DOES it.-

提交回复
热议问题