Understanding classes in Dart
If you are an experienced programmer or are already familiar with Java or similar languages, you can skip some parts of this chapter as it has many similarities with the typical OOP concepts, such as inheritance and encapsulation. Some ideas, in particular, are important to verify, even if you are already familiar with the majority of OOP features, such as how Dart manages and structures constructors.
In this section, we will look at what makes a Dart class, how you construct an instance of one using a constructor, and how your class can inherit from other classes. We will also explore ways to use classes such as abstract classes, interfaces, and mixins, and finally, look at how we share class code across our code base using files and imports.
Class structure
Dart classes are declared by using the class
keyword, followed by the class name, ancestor classes, and implemented interfaces. Then, the class body is enclosed by a pair of curly braces...