Smart Constructor

Noun · Development

Definitions

  1. A function that wraps the raw data constructor of a type and enforces additional invariants at construction time — returning an error or Maybe/Option if the input is invalid — so that any value of that type is guaranteed to be well-formed throughout the program.

    In plain English: A special factory function that only creates an object if the input is valid, so you can trust that every instance is correct by design.

    Example: "Use a smart constructor for EmailAddress that validates the format, so downstream code never has to re-check."

Related Terms