Skip to content

Instantly share code, notes, and snippets.

@daninfpj
Created June 28, 2019 19:10
Show Gist options
  • Save daninfpj/36807d3a7bb682b392ec7429aa96b6ff to your computer and use it in GitHub Desktop.
Save daninfpj/36807d3a7bb682b392ec7429aa96b6ff to your computer and use it in GitHub Desktop.
Polymorphism
class Movement {
String get status => 'COMPLETED';
bool get isForeignCurrency => false;
}
class Deposit extends Movement {}
class Charge extends Movement {
String status;
Charge({this.status});
bool get isForeignCurrency {
// if originalAmount…
return true;
}
}
void main() {
// From JSON, without status
final deposit = Deposit();
// FROM JSON, with status
final charge = Charge(status: 'PENDING');
print(deposit.status);
print(charge.status);
print(deposit.isForeignCurrency);
print(charge.isForeignCurrency);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment