O'Reilly logo

Dart 1 for Everyone by Chris Strom

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constructors

Dart gets a surprising amount of mileage out of its constructors. It does so through a combination of two types of constructors: generative and factory. The difference between the two has to do with how they create new objects. Generative constructors take care of blessing new objects for us, leaving us the task of initializing the internal state. In a factory constructor, we are responsible for building and returning new objects ourselves. As you will see, there is power in both the simplicity of generative constructors and the flexibility of factory constructors.

Generative constructors are the more common of the two, so we will talk about them first.

Simple Generative Constructors

Borrowing from Chapter 6, Project: MVC in Dart ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required