Concept · Intro

Abstraction

Expose WHAT something does through a simple interface, and hide HOW it does it. Abstraction fights complexity; encapsulation enforces it.

Asked atGoogleAmazonUber
step 1 / 9
1/2The simple face
uses
Driver
+ commute()
«interface»
Car
+ start()
+ accelerate()
+ brake()
PetrolCar
- pistons
- valves
- ecu
+ start()
+ accelerate()
+ brake()
- ignite()
- injectFuel()
The simple face
1interface Car {
2 start(); accelerate(); brake();
3}
4 
5class PetrolCar implements Car {
6 private pistons, valves, ecu;
7 brake() { ignite(); injectFuel(); ... }
8}
State
abstractionwhat, not how

Here is the abstraction: the Car interface. Three simple verbs — start, accelerate, brake. That is the entire surface anyone needs to know.