Browse OOP reference
Types and contracts

What are interfaces?

On this page

An interface specifies operations a consumer expects. A narrow Clock interface with now() lets a test choose the instant at which a lease expires. Specify whether now() represents wall-clock time or monotonically elapsed time. The type signature alone cannot answer that question.

Worked example

TypeScript
interface Clock { elapsed(): number }
function leaseExpired(clock: Clock, deadline: number): boolean {
  return clock.elapsed() >= deadline;
}
const manual = { elapsed: () => 10 };
if (!leaseExpired(manual, 10)) throw Error("Deadline is inclusive");

TypeScript Handbook on object types

Explore class relationships in the OOP Playground

What is UML?What is object-oriented programming?What is information hiding?

All OOP questions

Search ObjectFAQ