What's the difference between abstraction and encapsulation?

前端 未结 24 1026
攒了一身酷
攒了一身酷 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:07

    Abstraction refers to the act of representing essential features without including the background details or explanations.

    Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.

    Difference between abstraction and encapsulation

    1.Abstraction focuses on the outside view of an object (i.e. the interface) Encapsulation (information hiding) prevents clients from seeing it’s inside view, where the behavior of the abstraction is implemented.

    2.Abstraction solves the problem in the design side while Encapsulation is the Implementation.

    3.Encapsulation is the deliverable of Abstraction. Encapsulation barely talks about grouping up your abstraction to suit the developer needs.

提交回复
热议问题