Skip to content

Instantly share code, notes, and snippets.

@kenzieschmoll
Created June 20, 2019 20:26
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 kenzieschmoll/40f24d233b9aeb9d3a62eb40a5aadd63 to your computer and use it in GitHub Desktop.
Save kenzieschmoll/40f24d233b9aeb9d3a62eb40a5aadd63 to your computer and use it in GitHub Desktop.
Class name reporting
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