0PricingLogin
Dart Academy · Lesson

Named Constructors for Clear Intent

Offer multiple ways to construct.

Why Named Constructors

One class often needs several ways to be built. A named constructor gives each path a clear label so callers know exactly what they get.

The Naming Syntax

Write the class name, a dot, then your label. The form ClassName.label reads like a tiny sentence at the call site.

class Point {
  int x, y;
  Point.origin() : x = 0, y = 0;
}

All lessons in this course

  1. Default and Parameterized Constructors
  2. Named Constructors for Clear Intent
  3. Initializer Lists and Redirecting
  4. Factory and const Constructors
← Back to Dart Academy