encapsulation vs abstraction real world example

前端 未结 17 2199
闹比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:56

    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.

提交回复
热议问题