Created with <3 with dartpad.dev.
Created
October 4, 2023 13:25
-
-
Save MelvinRB27/8a9f538fe85e571d776f5234ab2827d1 to your computer and use it in GitHub Desktop.
Get, Set, Assert
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
void main() { | |
final v = Square(side: -27); | |
//v.set(-2.5); | |
print( v.area ); | |
} | |
class Square { | |
double _side; | |
Square({required double side}) | |
: assert(side >= 0, 'side must be >= 0'), | |
_side = side; | |
double calculate() { | |
return _side * _side; | |
} | |
double get area { | |
//return _side * _side; | |
return calculate(); | |
} | |
set(double value) { | |
if (value < 0) throw 'value must be >= 0'; | |
_side = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment