Skip to content

Instantly share code, notes, and snippets.

@MelvinRB27
Created October 4, 2023 13:25
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 MelvinRB27/8a9f538fe85e571d776f5234ab2827d1 to your computer and use it in GitHub Desktop.
Save MelvinRB27/8a9f538fe85e571d776f5234ab2827d1 to your computer and use it in GitHub Desktop.
Get, Set, Assert
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