← Map
Dart Island · Level 8
Learn Flutter

Abstraction & Encapsulation

Abstraction means hiding complexity behind a simple interface — you use a remote control without knowing its circuit. Encapsulation means bundling data with methods and controlling access to protect the data.
12 games from black boxes to building fully safe classes.
Core ideas

In Dart, add _ before a name to make it private to its library. Use getters to expose controlled read access.

class BankAccount {
// Private — only accessible inside this class
double _balance = 0;
// Public getter — controlled access
double get balance => _balance;
void deposit(double amount) {
if (amount > 0) _balance += amount;
}
}
  • _name — private field, hidden from outside
  • get balance — controlled read-only access
  • abstract class — defines a contract, cannot be created directly
  • implements — a class must fulfill an abstract class's contract
Progress
0 / 12 mini-games solved
Stage 1

Black Box

Predict output from a function's API without seeing its code.

Abstraction: you don't need to know how it works — just what it does. Predict the output from the function's API.

// You only see the signature, not the body:
int square(int n);
print(square(20)); // ?

What does square(20) return? (It squares its input)

Island map