Programming/Language/Concept/Interface
Properties
Interface (programming language)
- An interface is a named contract: operations callers may rely on without fixing one implementation. Program to an interface, not an implementation.
- The name stabilizes vocabulary:
Vehicle,PaymentMethod,UserRepository, with many concrete types behind it (Car,Truck, …). Nominal and structural
- Nominal typing — the type declares the relationship (
class Car implements Vehicle,extends,impl Vehicle for Car, explicit protocol conformance). - Structural typing — the value matches the interface type without a declaration if its shape fits. Typescript and Go are the everyday examples.
- Interface names the boundary; nominal vs structural names how the checker enforces it.
- Nominal typing — the type declares the relationship (
Narrowing
- A parameter typed to a smaller contract hides extra methods on the concrete value. Callers only see what
Vehiclepromises, even ifCaralso hasopenTrunk(): def planRoute(v: Vehicle) = ...- Related vocabulary: interface narrowing, upcasting, capability typing, information hiding at the type boundary.
- Any static language with subtyping or interface types supports this; it is discipline about which type you expose, not a separate type system.
- A parameter typed to a smaller contract hides extra methods on the concrete value. Callers only see what
Keywords by ecosystem
Interfaces and type classes
- Nominal vs structural is one axis. Another is where the operations live:
Where does the behavior live? on the value (methods) vs outside the value (instances / dictionaries) interface / trait methods type class / given / instance- Interface / trait —
car.honk(); behavior on the receiver. - Type class constraints — evidence that operations exist for
T, often passed separately. Example types:Carwithhonkmediated by a type-class instance: - Advanced Scala / FP also encodes “has these operations” with traits + generics, tagless final, and similar; those designs overlap type classes and compete with plain Java-style interfaces.
Scala
Terminology