Created
June 20, 2019 20:26
-
-
Save kenzieschmoll/40f24d233b9aeb9d3a62eb40a5aadd63 to your computer and use it in GitHub Desktop.
Class name reporting
This file contains 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'; | |
class Position { | |
int x; | |
int y; | |
double distanceTo(Position other) { | |
var dx = other.x - x; | |
var dy = other.y - y; | |
// Code to throw an error so we can see the class name. | |
try { | |
throw Error; | |
} on Error catch (e) { | |
print(e.stackTrace); | |
} | |
return sqrt(dx * dx + dy * dy); | |
} | |
} | |
class Square { | |
int width; | |
int height; | |
int get area => width * height; | |
} | |
// Classes can be mixed in using 'with' | |
class SquareView extends Square with Position {} | |
main() { | |
var origin = new Position() | |
..x = 0 | |
..y = 0; | |
var square = new SquareView() | |
..x = 5 | |
..y = 5 | |
..width = 10 | |
..height = 10; | |
print(square.distanceTo(origin)); | |
print(square.area); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment