Chapter 6. Constructing classes and interfaces

 

This chapter covers

  • Defining classes
  • Dart’s implied interfaces
  • Constructing classes

Dart is a single-inheritance, class-based, object-oriented language. It has many similarities to Java and C# in terms of its class and interface mechanisms. In this chapter, we’ll look at the features of Dart’s classes that enable you to design flexible libraries of classes and interfaces that promote best practices, such as coding against interfaces and providing named constructors for different, specific purposes.

We’ll deal with the different ways to construct classes, including what appears to be the ability to construct an instance of an abstract class, rather than a specific implementation class, and why you might get the same instance of an object back when calling a constructor. In the discussion of factory constructors, we’ll also look at static properties and methods, which share their state across all instances of a class. When we get to constant constructors, you’ll see that you must use them in conjunction with final, read-only properties to provide a simple way to create fixed, unchanging class instances.

6.1. Defining a simple class

6.2. Constructing classes and interfaces

6.3. Creating constant classes with final, unchanging variables

6.4. Summary

sitemap