What's the difference between abstraction and encapsulation?

前端 未结 24 1135
攒了一身酷
攒了一身酷 2020-12-22 17:16

In interviews I have been asked to explain the difference between abstraction and encapsulation. My answer has been along the lines of

  • Abstraction<

24条回答
  •  不知归路
    2020-12-22 18:05

    Difference between Abstraction and Encapsulation :-

    Abstraction

    1. Abstraction solves the problem in the design level.
    2. Abstraction is used for hiding the unwanted data and giving relevant data.
    3. Abstraction lets you focus on what the object does instead of how it does it.
    4. Abstraction- Outer layout, used in terms of design. For Example:- Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.

    Encapsulation

    1. Encapsulation solves the problem in the implementation level.
    2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world.
    3. Encapsulation means hiding the internal details or mechanics of how an object does something.
    4. Encapsulation- Inner layout, used in terms of implementation. For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.

提交回复
热议问题