We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Abstraction vs. Encapsulation Quiz

Academics love to split hairs about definitions... but in practice, we're basically talking about the same thing here.

The terms "abstraction" and "encapsulation" mostly just emphasize different aspects of the same concept:

  • Abstraction focuses on exposing essential features while hiding complexity
  • Encapsulation focuses on bundling data with methods and restricting direct access to implementation details

Creating good abstractions is particularly crucial when you're developing libraries for other developers to use. For example, the built-in pow function in Python is an abstraction that hides the complexity of calculating exponents.

pow isn't magic. Somewhere, code that does something like this exists and is called when you use pow:

def pow(base: int, exponent: int) -> int:
    result = 1
    for _ in range(exponent):
        result *= base
    return result