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 ...

Get Dart 1 for Everyone now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.