Browse OOP reference
Objects and behaviour

What is information hiding?

On this page

Information hiding arranges a module around a decision likely to change. A schedule service can expose next_departure(stop, instant) while privately changing its index from a sorted array to a tree. Its boundary succeeds if the change leaves callers and their tests alone.

Worked example

Python
from bisect import bisect_left

class Departures:
    def __init__(self, minutes):
        self._sorted = sorted(minutes)

    def next_at(self, minute):
        i = bisect_left(self._sorted, minute)
        return self._sorted[i] if i < len(self._sorted) else None

board = Departures([25, 3, 14])
assert board.next_at(14) == 14 and board.next_at(26) is None

Python tutorial on classes

Explore class relationships in the OOP Playground

What is object-oriented programming?How does object-oriented design apply to AI engineering?What is encapsulation?

All OOP questions

Search ObjectFAQ