Abstract Data Type (ADT)

Context: FIT1008_MOC · the pure-specification rung of the abstraction ladder · becomes a Data Type once implemented · realised by a Data Structure

Quick Revision

  • 🎯 Objective: specify what a type does (values, meaning, operations), not how ➔ program against the interface, swap implementations freely.
  • 📦 Core Components: a contract ➔ operations + pre/post-conditions + invariant, hardened by encapsulation.
  • ⚡ Key Constraint: decouples interface from cost ➔ the same ADT has implementations with different complexity profiles.

📝 Core

1. The ADT (What, Not How)

  • Specification ➔ values + meaning + operations, no implementation (Stack (ADT) = push/pop/peek, backing irrelevant).
  • Abstraction = ignoring ➔ the user chooses to ignore the implementation.
  • Encapsulation ➔ enforces it so callers cannot depend on internals.

2. The Contract (Design-by-Contract)

  • Contract ➔ operations + preconditions + postconditions + an Invariant each preserves.
  • Substitutability ➔ any implementation may replace another if it honours the same contract.
  • Boundary ➔ violating encapsulation (poking internals) forfeits substitutability.

⚙️ Core Implementation

🔹 Programming against the contract

⚖️ Core Decision Matrix

AdvantageWhat it buysTrade-off
Simplicityreason about operations, not bytessmall indirection
Maintainabilitychange impl without touching clientscan hide a poor impl choice
Flexibilityswap array ↔ linked freelyrequires honouring the contract
Portabilityone interface across machines/langs

When It Flips: interface ≠ cost — a Priority Queue (ADT) is / as a sorted list but / as a Heap; choosing the implementation to fit the workload is the central design act.

📊 Exam Execution Trace

Manual Execution Trace

Same ADT (Priority Queue (ADT)), different implementation costs:

Step / StateImplementationaddget_max
0 (Init)(ADT interface)
1sorted list
2Heap
3Fibonacci heap amortised

Applied Exercise

Problem: Justify why two implementations of an ADT are freely substitutable. Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: substitutability follows from contract conformance, not shared code — the whole point of separating ADT from data structure.

🧠 Active Recall