interface
A named set of member signatures that a type promises to implement, with no state of its own.
In more detail
Code that depends on an interface can be given any implementation, including a test double, which makes components easy to swap. Some languages, such as Java and C#, require a type to declare the interfaces it implements, while others, such as Go and TypeScript, match them by shape. In TypeScript, interfaces exist only at type-checking time and are removed before the code runs.
Examples
C#: interface names start with I by convention, as in IProductRepository.In the browser: In TypeScript an interface such as interface BoxSpec { contentWidth: number } lets the compiler check that objects have the right fields. Web specifications also use the word: EventTarget and Performance are interfaces that browser objects implement.interface User { id: string; name: string }type Reporter interface {
Report() string
}Go: type Reporter interface { Report() string }Related terms
- abstraction — A simplified description of what something does, such as an interface, that hides how it does it.
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
- default interface member — A method with a body declared on an interface itself, inherited by every implementing class that does not replace it.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- TypeScript — JavaScript with added type annotations, checked by a compiler before the code runs.
- EventTarget — The built-in browser interface for anything that can receive events, providing addEventListener, removeEventListener and dispatchEvent.
- validation schema — A description of what valid data looks like, checked by code while the program runs so bad data is rejected at the door.
- DTO — A plain object whose only job is to carry data across a boundary, such as the body of an API request or response.
- implicit interface satisfaction — Go's rule that a type meets an interface just by having the right methods, with no implements declaration.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- empty interface — The interface with no methods, spelled any or interface{}, which every Go type satisfies.
- type assertion — An expression such as value.(string) that gets the concrete value out of an interface, if it really holds that type.
- io.Reader — The Go interface for anything you can read bytes from, such as a file, a network connection or an HTTP response body.
- props — The inputs passed to a component, written like HTML attributes, such as <Avatar size={48} />.
- object — A single thing created from a class or other type, holding its own values and able to run the type's methods.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- The Dependency Injection Container: Scopes and Lifetimes — Modern .NET Core, C# & Enterprise Microservices
- The Repository Pattern — Modern .NET Core, C# & Enterprise Microservices
- Layout, Reflow, Paint And GPU Compositing Layers — Frontend Architecture & Web Platform
- Modern Box Model, Box Sizing, Display Types And Flow Layout — Frontend Architecture & Web Platform
- CustomEvent Dispatching And Decoupled Component Event Buses — Frontend Architecture & Web Platform
- Monorepo Architecture: Workspaces & Turborepo — Production Full-Stack Engineering
- End-to-End Type Safety: Shared Schemas & DTOs — Production Full-Stack Engineering
- Type-Safe RPC Architectures: tRPC & Procedures — Production Full-Stack Engineering
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Interfaces and Why They Are Implicit — Concurrent Systems Programming with Go
- Type Assertions and the Empty Interface — Concurrent Systems Programming with Go
- The Standard testing Package — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go
- Streams and the io Package — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go
- App Router Architecture: Server-First Paradigms — Next.js 15 & Modern App Router Architecture
- Server Components: Async Execution & Constraints — Next.js 15 & Modern App Router Architecture
- Client Components: use client & Hydration Models — Next.js 15 & Modern App Router Architecture
- Component Tree Composition: Interleaving RSC & Client — Next.js 15 & Modern App Router Architecture
- Loading UI: Instant Loading States with loading.tsx — Next.js 15 & Modern App Router Architecture
- Streaming Endpoints: Server-Sent Events & NDJSON Feeds — Next.js 15 & Modern App Router Architecture
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services