A Beginners Guide to Dart - Methods, Final, Static, and Class Inheritance - Part Four
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
Hi @tensor,
This is another great addition to the series of the videos on Dart.
It is great that you are developing this series slowly one by one for the beginners.
This will definitely be able to help them get started.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
As always thanks for moderating my contributions.
Thank you for your review, @rosatravels! Keep up the good work!
Hi @tensor!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
This post has been voted on by the SteemSTEM curation team and voting trail in collaboration with @curie.
If you appreciate the work we are doing then consider voting both projects for witness by selecting stem.witness and curie!
For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!
Hi, @tensor!
You just got a 6.27% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
Hey, @tensor!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Hello @tensor! This is a friendly reminder that you have 3000 Partiko Points unclaimed in your Partiko account!
Partiko is a fast and beautiful mobile app for Steem, and it’s the most popular Steem mobile app out there! Download Partiko using the link below and login using SteemConnect to claim your 3000 Partiko points! You can easily convert them into Steem token!
https://partiko.app/referral/partiko