This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Static methods and variables in Dart (as of v2.5) | |
// See live at https://dartpad.dartlang.org/300a5a59fc1209aaa6bbbc1f1427bc4a | |
void main() { | |
print('Moon mass: ${Moon.mass}'); | |
print('Moon mass scaled down by 10 is ${Moon.getScaledMass(10)}'); | |
print('Moon mass scaled up by 10 is ${Moon.getScaledMass(10, false)}'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Interfaces in Dart (as of v2.5) | |
// See live at https://dartpad.dartlang.org/19a8c3c203f27fd1820c004582480ff5 | |
/* | |
* TLDR; | |
* There is no interface keyword in Dart. Instead we use a regular class with either the extends or | |
* implements keyword. If a subclass uses the extends keyword, the child class inherits from the | |
* parent class normally. Else, if the subclass uses the implements keyword, the parent class is | |
* treated as an interface: all inherited members must be overriden. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Abstract classes and methods in Dart (as of v2.5) | |
// See live at https://dartpad.dartlang.org/847473dc3db9ba5ad9848ecf7b00ba7e | |
void main() { | |
// Expect Error! - Can't instantiate abstract classes | |
// final Person p = Person(); | |
final Person sartre = Philosopher(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inheriting from default and named constructors in Dart (as of v2.5) | |
// See live at https://dartpad.dartlang.org/4882c662c9cb6bb13ce358b5cffe0968 | |
void main() { | |
final Van myVan = Van("Toyota", "Odyssey"); | |
print('Color: ${myVan.color}'); | |
print('Make: ${myVan.make}'); | |
print('Model: ${myVan.model}'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic inheritance and polymorphism in Dart (as of v2.5) | |
// see https://dartpad.dartlang.org/030764a47bc7599b0e1853bda75c7639 | |
void main() { | |
print(''); | |
print('------------------ Tree object, Tree Reference ----------------------'); | |
print(''); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
// Object Oriented Programming Concepts in Dart ( as ov v2.5) | |
// Private Variables and Getters/Setters in Dart | |
// see https://dartpad.dartlang.org/4624e4394c7b09ae5430764abe71d8f3 | |
void main() { | |
// Default getters/setters. Though it looks like we are directly manipulating the instance variable, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://dartpad.dartlang.org/6f21c9137b5b14a86025aa5d7dcb7d75 | |
// Frequency Counter pattern in Dart | |
void main() { | |
/** | |
* Problem Description: | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Constructors in Dart (as of v2.5) | |
// This example can be run at https://dartpad.dartlang.org/fc100517efced76881fd0d8d37f673a8 | |
// For other examples see https://gist.github.com/kirkdrichardson | |
void main() { | |
// Use the default constructor | |
final Car c = Car(); | |
print('Car with default constructor id: ${c.id}'); | |
print('\n\n'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exception Handling in Dart (since v2.2) | |
// This example can be run at https://dartpad.dartlang.org/4d61e7617f5ea82b73223e75242ed368 | |
// For other examples see https://gist.github.com/kirkdrichardson | |
void main() { | |
// 🚫 Expect Error! | |
// int myInt = 40 / 10; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Looping and Iteration in Dart (since v2.2) | |
// No surprises here. | |
// This example can be run at https://dartpad.dartlang.org/880e763c99d49f238578de39d5a49bdd | |
// For other examples see https://gist.github.com/kirkdrichardson | |
void main() { | |
// O(n) version of n(n+1)/2 series, i.e. the sum of 1 + 2 + 3 + 4...n |