Created
June 28, 2019 19:10
-
-
Save daninfpj/36807d3a7bb682b392ec7429aa96b6ff to your computer and use it in GitHub Desktop.
Polymorphism
This file contains hidden or 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
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