Encapsulation

Encapsulation hides a class's internal state: fields are private and accessible only through public methods (accessors, business methods) that guarantee the validity rules. It protects the object's invariants and lets you change the implementation without breaking calling code.

Example

class Compte {
    private double solde;
    public double getSolde() { return solde; }
}

Related concepts

The whole glossary