Abstraction

Abstraction#

Abstraction means that the user interacts with only selected attributes and methods of an object. Abstraction uses simplified, high level tools, to access a complex object.

  • Using simple things to represent complexity

    • Objects, classes represent more complex underlying code

  • Hide complex details from user

Abstraction is using simple classes to represent complexity. Abstraction is an extension of encapsulation. For example, you don’t have to know all the details of how the engine works to drive a car. A driver only uses a small selection of tools: like gas pedal, brake, steering wheel, blinker. The engineering is hidden from the driver. To make a car work, a lot of pieces have to work under the hood, but exposing that information to the driver would be a dangerous distraction. widget

Abstraction also serves an important security role – by only displaying selected pieces of data, and only allowing data to be accessed through classes and modified through methods, the developer protects the data from exposure. To continue with the car example, you wouldn’t want an open gas tank while driving a car.

Benefits of abstraction:#

  • Simple, high level user interfaces

  • Complex code is hidden

  • Security

    • Only chosen parts of object are accessible

  • Easier software maintenance

    • Code updates rarely change abstraction