Repository
https://github.com/dart-lang/sdk
What Will I Learn?
- You will learn about Operator Methods, Class Methods and Object Methods
- You will learn about the Final keyword
- You will learn about the Static keyword and Static methods
- You will learn about Class Inheritance and overriding custom methods
- You will learn how to call to super methods from child classes
Requirements
System Requirements:
- IDEA intellij or Visual Studio Code with the Dart Plugins
- The Dart SDK
OS Support for Dart:
- Windows
- macOS
- Linux
Required Knowledge
- The Dart SDK
- A Dart supported text editor (Dart Pad can be used)
- A little time to sit and watch a video and some patience to learn the language
Resources for Dart:
- Dart Website: https://www.dartlang.org/
- Dart Official Documentation: https://www.dartlang.org/guides/language/language-tour
- Dart GitHub repository: https://github.com/dart-lang/sdk
- Awesome Dart GitHub Repository: https://github.com/yissachar/awesome-dart
- Pub website: https://pub.dartlang.org
Sources:
Dart Logo (Google): https://www.dartlang.org/
Difficulty
- Beginner
Description
In this Dart beginner's video tutorial, we extend our knowledge of classes by adding more functionality to the Complex Number class that we were building from the last video. We build custom operator methods, custom class methods and object methods. We take a look at the final
and static
keywords and how they relate to classes and objects. We also look at basic class inheritance via the extends
keyword. This includes overriding constructors and methods as well as calling parent methods via the super
keyword.
Building Methods in Classes
In Dart, classes allow you to define properties for modeling your data. The fields of a class allow you to specify the shape and size of the data itself and the methods allow you to define how this data can be used, manipulated and interfaced with. These methods can include static methods which are tied to the main class, object methods which can be deployed from any object instance and operator methods which make use of existing operators in Dart.

In the above image, are examples of these three different styles of methods. At the top is an operator method that makes use of the +
operator. This method can be invoked by adding two complex objects together using this operator. The multiply
method is just a basic object method. This method can be called from any instance of the complex object class and it requires a single parameter to be passed into it. Finally, we have the static or class based subtract method. This method is attached to the complex class and therefore must be called from the class and not an instance of the class.
Basic Class Inheritance in Dart
In Class based programming, the idea of inheritance, is to allow another class to share certain behaviors as a parent class. In Dart, classes are allowed to inherit from exactly one parent class aside from the basic Object
type which is implicit. When a class inherits from another class, it gains the fields and methods that are defined in that parent class unless they are specifically overridden.

In the above image, we defined a class called quaternion
. Quaternions are an extension of Complex Numbers and therefore, it makes sense to use the basic Complex number Class as a template for defining the Quaternion behavior. In this class, we add a third field, jImage
and we can use the other two fields defined in the Complex class as though they were a part of the Quaternion class. Notice that the constructor calls to super
in the initializer list; this means that it class to the complex number constructor to build the real and imaginary fields in this class. Also, notice that we override the toString
method to account for this extra jImage
field.
The Source Code for this video may be found here: https://github.com/tensor-programming/dart_for_beginners/tree/tensor-programming-patch-3