Created with <3 with dartpad.dev.
Created
July 22, 2022 10:42
-
-
Save faizan1947/ac1d73d8cc58c0ebf9ebb73605845fdf to your computer and use it in GitHub Desktop.
Function as first order object
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() { | |
//Crate Car object | |
Car myCar = Car(drive: slowDrive); | |
//myCar.drive!(); | |
//Now lets say upgrade car | |
myCar.drive = fastDrive; | |
myCar.drive!(); | |
} | |
class Car{ | |
Car({this.drive}); | |
Function? drive; | |
} | |
//Top level functions , not associated with class | |
void slowDrive(){ | |
print("Slowly driving"); | |
} | |
void fastDrive(){ | |
print("Driving Fast"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment