Skip to content

Instantly share code, notes, and snippets.

@devzom
Created March 29, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devzom/2e129644623d42f3b7d6a737a0e001bf to your computer and use it in GitHub Desktop.
Save devzom/2e129644623d42f3b7d6a737a0e001bf to your computer and use it in GitHub Desktop.
Testing Dart basics
//////////// abstract classes, interfaces, mixins
enum TeacherType { mathematican, biologist, physics }
abstract class Person {
TeacherType teacherType;
void teach();
}
mixin Language {
bool knowsLanguages;
bool doesKnowLanguage() => knowsLanguages;
}
class Teacher extends Person with Language {
TeacherType teacherType = TeacherType.biologist;
Teacher() {
knowsLanguages = false;
}
@override
void teach() {
print('This teacher is a ${teacherType} ');
}
}
void main() {
final Joe = Teacher().teach();
}
///////// abstract classes, interfaces, mixins
// class inheritance
// class Animal {
// String race;
// int legsCount;
// Animal(this.race, this.legsCount);
// String get animalInfo => 'It\'s $race and have $legsCount legs.';
// @override
// String toString() => animalInfo;
// }
// class HomePet extends Animal{
// var petKind = <String>[];
// HomePet(String race, int legsCount) : super(race, legsCount);
// @override
// String get animalInfo => '$race it\'s a homepet and have $legsCount legs and can sleep on couch';
// }
// // class inheritance
// void main() {
// final animal = Animal("dog", 4);
// final dog = HomePet("dog", 4);
// print(animal);
// print(dog);
// //
// }
// static classes member
// enum NaturePower { water, air, earth, fire }
// class Heroes {
// String name;
// NaturePower powertype;
// //internal constructor
// Heroes._internal(this.name, this.powertype);
// //property
// static var heroesCount = 0;
// //method
// static Heroes newHeroes(String name, NaturePower powertype) {
// heroesCount++;
// return Heroes._internal(name, powertype);
// }
// }
// void main() {
// //
// final Thor = Heroes.newHeroes("Thor Arr", NaturePower.earth);
// final Two = Heroes.newHeroes("TwoMan", NaturePower.air);
// print(Thor.name);
// print(Heroes.heroesCount);
// }
// static classes member
// // classes and objects
// class Person {
// String name;
// var favoriteMovies = <String>[];
// Person(this.name, this.favoriteMovies);
// Person.rey({this.name = "Jacob"}) {
// favoriteMovies = ["Avengers"];
// }
// Person.details(String name, List<String> favoriteMovies)
// : this.name = name,
// this.favoriteMovies = favoriteMovies {
// var _personInfo =
// "Person name: ${this.name} | Favorite movies list: ${this.favoriteMovies}";
// print(_personInfo);
// }
// //getters and setters
// String get favMovie => "Favorite favMovie: ${this.favoriteMovies}";
// set favMovie(String favMovie) => favoriteMovies.insert(0, favMovie);
// void addFavMovie(String movieName) {
// favoriteMovies.add(movieName);
// print(movieName);
// }
// }
// void main() {
// var personOne = new Person("Jacob", ["Avengers"]);
// print(personOne.name);
// // var personInfo = new Person.details("Jacob", ["1", "2", "3"]);
// // print(personOne.favMovie);
// personOne.addFavMovie("Star Trekx2000");
// // print(personOne.favMovie);
// personOne
// ..name
// ..addFavMovie("Shrek");
// print(personOne.favMovie);
// }
// // classes and objects
// //MAP
// // Map<String, String> heroes = {"Iron Man": "Suit", "Thor": "Hammer"};
// // String ironManPower = heroes["Iron Man"];
// // print(ironManPower);
// // print("======");
// // // heroes.keys.forEach(print);
// // heroes.forEach((key, value) => print('$key: $value'));
// //MAP
// // LIST
// // List<int> price = [10,20,30,40];
// // int totalAmount = price.reduce((price, element) => price + element);
// // print(totalAmount);
// // SETS
// // var intSet = <int>{};
// // var someSet = {1, 2, 3, 4, 5};
// // intSet.add(1);
// // print(intSet);
// // print(someSet);
// // var interSectionSet = intSet.intersection(someSet);
// // print('interSectionSet value: $interSectionSet');
// // var unionSet = intSet.union(someSet);
// // print('unionSet value: $unionSet');
// // sets
// // }
// static classes member
// enum NaturePower { water, air, earth, fire }
// class Heroes {
// String name;
// NaturePower powertype;
// //internal constructor
// Heroes._internal(this.name, this.powertype);
// //property
// static var heroesCount = 0;
// //method
// static Heroes newHeroes(String name, NaturePower powertype) {
// heroesCount++;
// return Heroes._internal(name, powertype);
// }
// }
// void main() {
// //
// final Thor = Heroes.newHeroes("Thor Arr", NaturePower.earth);
// final Two = Heroes.newHeroes("TwoMan", NaturePower.air);
// print(Thor.name);
// print(Heroes.heroesCount);
// }
// static classes member
// // classes and objects
// class Person {
// String name;
// var favoriteMovies = <String>[];
// Person(this.name, this.favoriteMovies);
// Person.rey({this.name = "Jacob"}) {
// favoriteMovies = ["Avengers"];
// }
// Person.details(String name, List<String> favoriteMovies)
// : this.name = name,
// this.favoriteMovies = favoriteMovies {
// var _personInfo =
// "Person name: ${this.name} | Favorite movies list: ${this.favoriteMovies}";
// print(_personInfo);
// }
// //getters and setters
// String get favMovie => "Favorite favMovie: ${this.favoriteMovies}";
// set favMovie(String favMovie) => favoriteMovies.insert(0, favMovie);
// void addFavMovie(String movieName) {
// favoriteMovies.add(movieName);
// print(movieName);
// }
// }
// void main() {
// var personOne = new Person("Jacob", ["Avengers"]);
// print(personOne.name);
// // var personInfo = new Person.details("Jacob", ["1", "2", "3"]);
// // print(personOne.favMovie);
// personOne.addFavMovie("Star Trekx2000");
// // print(personOne.favMovie);
// personOne
// ..name
// ..addFavMovie("Shrek");
// print(personOne.favMovie);
// }
// // classes and objects
// //MAP
// // Map<String, String> heroes = {"Iron Man": "Suit", "Thor": "Hammer"};
// // String ironManPower = heroes["Iron Man"];
// // print(ironManPower);
// // print("======");
// // // heroes.keys.forEach(print);
// // heroes.forEach((key, value) => print('$key: $value'));
// //MAP
// // LIST
// // List<int> price = [10,20,30,40];
// // int totalAmount = price.reduce((price, element) => price + element);
// // print(totalAmount);
// // SETS
// // var intSet = <int>{};
// // var someSet = {1, 2, 3, 4, 5};
// // intSet.add(1);
// // print(intSet);
// // print(someSet);
// // var interSectionSet = intSet.intersection(someSet);
// // print('interSectionSet value: $interSectionSet');
// // var unionSet = intSet.union(someSet);
// // print('unionSet value: $unionSet');
// // sets
// // }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment