jargon

Comparison

NominalvsStructural typing

Nominal

Nominal typing decides compatibility by the declared name — a type fits only if it says it does.

Structural typing

the object had every method the interface asked for and the compiler still refused it, because it had not said it implemented it.

Nominal typing decides compatibility by the declared name — a type fits only if it says it does; structural typing decides by shape — a type fits if it has the right members. It explains why the same code is accepted by one language and rejected by another, and why interfaces feel heavier in some ecosystems than others. Structural typing makes test doubles and adapters nearly free; nominal typing makes the intent explicit and catches accidental compatibility.

Full entry →

The difference

Nominal typing decides compatibility by the declared name — a type fits only if it says it does; structural typing decides by shape — a type fits if it has the right members. It explains why the same code is accepted by one language and rejected by another, and why interfaces feel heavier in some ecosystems than others. Structural typing makes test doubles and adapters nearly free; nominal typing makes the intent explicit and catches accidental compatibility.

Entry: Nominal vs structural typing

Related comparisons