Created with <3 with dartpad.dev.
Last active
March 29, 2023 14:43
-
-
Save mit-mit/34634527fbabb24f85e3b44db6f9a756 to your computer and use it in GitHub Desktop.
grandiose-rainbow-2989
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' 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