Interface design
Introduction / Definition
An interface defines how clients use a component without exposing its internal representation. A good interface is small, consistent, and predictable. It specifies operations, inputs, outputs, and errors. This reduces coupling and makes implementations replaceable.
Syntax / Structure / Formula
interface ADT { operation signatures }
Detailed Explanation
A stack interface can expose push, pop, peek, and isEmpty while hiding whether storage uses an array or linked nodes.
Example
Example: Stack<T>: push(T), pop(), peek(), isEmpty().
Output / Result
Client code depends on the contract rather than storage.
Important Points / Notes
- Hide implementation details.
- Document contracts and errors.
Mini Practice Question
List four stack interface operations.