Skip to content

Instantly share code, notes, and snippets.

@mit-mit
Last active March 29, 2023 14:43
Show Gist options
  • Save mit-mit/34634527fbabb24f85e3b44db6f9a756 to your computer and use it in GitHub Desktop.
Save mit-mit/34634527fbabb24f85e3b44db6f9a756 to your computer and use it in GitHub Desktop.
grandiose-rainbow-2989

grandiose-rainbow-2989

Created with <3 with dartpad.dev.

import 'dart:math' as math;
sealed class Shape {
}
class Square extends Shape {
final double length;
Square(this.length);
}
class Circle extends Shape {
final double radius;
Circle(this.radius);
}
double calculateArea(Shape shape) =>
switch (shape) {
Square(length: var l) => 0,
Circle(radius: var r) => 0
};
main() {
Shape s = Square(4);
print('Area of Square(4): ${calculateArea(s)}.');
s = Circle(5);
print('Area of Circle(5): ${calculateArea(s)}.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment