What's the difference between abstraction and encapsulation?

前端 未结 24 1128
攒了一身酷
攒了一身酷 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 17:48

    As far as iOS is concerned, it can be said that Objective C files (i.e. .h and .m) use abstraction as well as encapsulation.

    Abstraction

    Header file (.h) only exposes the functions and public members to outside world. No one knows how they are used unless they have the implementation file with them. It is the .m file that holds all the usage and implementation logic with it self. "Implementation remains unexposed".

    Encapsulation

    The property (@property) encapsulates the memory management attribute (atomic, strong, retain, weak) of an iVar.

提交回复
热议问题