Book Image

Mastering Dart

By : Sergey Akopkokhyants
Book Image

Mastering Dart

By: Sergey Akopkokhyants

Overview of this book

Table of Contents (19 chapters)
Mastering Dart
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Summary


In this chapter, you learned that a constructor is a method that is invoked to create an object from a class. There are generative and factory constructors. The main purpose of a generative constructor is to initialize the instance of a class in a safe manner. The constructor can have required or optional parameters. The optional parameters enable the supply of arguments for only a few parameters from the list of optional parameters.

A constructor can be named. The named constructors provide intuitive and safer construction operations, because named constructors have similar code and some of them can be translated into redirecting constructors. A redirecting constructor calls another constructor that makes the code compact.

Dart supports private constructors. If a class has only private constructors, Dart cannot create an instance of a class. Private constructors are usually used in classes that contain static members, which are only useful in combination with the factory constructor...