Advanced Topics · Compiler Design

Data Abstraction

Watch lectures

Data Abstraction

1. Meaning

Data abstraction hides representation behind an interface: clients see ops + contract, compiler enforces encapsulation (private fields, opaque types). Enables modular reasoning + optimization.

2. Mechanisms by Language

Feature How compiled
Struct/class record layout + access checks (private rejected)
Abstract data type opaque pointer; only interface funcs linked
Module/package symbol visibility (export list); hidden names mangled/local
Generic/template monomorphize per instantiation or box + dictionary
Immutable no writes → safe sharing, const propagation

3. Example — stack ADT

interface: push(x), pop(), top()   // client sees only this
impl: array + top index (hidden)
compile: client calls → CALL push; direct field access → error: private
opt: small push inlined; representation change needs no client recompile (if ABI stable)

4. Compiler Responsibilities

Check visibility, lay out hidden state, generate dispatch (static for structs, dynamic for objects), preserve invariants (e.g. top in range).

5. Exam Points

  • Define abstraction + encapsulation — 5 marks, frequent.
  • ADT compile strategy with example — 5 marks, frequent.
  • Generics: monomorphize vs boxing — 3 marks, frequent.
Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.

← All Compiler Design modules

Data Abstraction — Compiler Design — PYQDeck