Simple way to understand Encapsulation and Abstraction

后端 未结 15 1209
谎友^
谎友^ 2020-11-27 09:47

Learning OOP concepts especially interested to understand Abstraction and Encapsulation in depth.

Checked out the below already

Abstraction VS Information Hi

15条回答
  •  半阙折子戏
    2020-11-27 10:52

    Abstraction is hiding the information or providing only necessary details to the client.

    e.g Car Brakes- You just know that pressing the pedals will stop the vehicle but you don't need to know how it works internally.

    Advantage of Abstraction Tomorrow if brake implementation changes from drum brake to disk brake, as a client, you don't need to change(i.e your code will not change)

    Encapsulation is binding the data and behaviors together in a single unit. Also it is a language mechanism for restricting access to some components(this can be achieved by access modifiers like private,protected etc.)

    For e.g. Class has attributes(i.e data) and behaviors (i.e methods that operate on that data)

提交回复
热议问题