Created with <3 with dartpad.dev.
Created
July 14, 2022 07:51
-
-
Save darknight1604/0055af404422f905ea435af4e885624d to your computer and use it in GitHub Desktop.
fascinating-dryad-3978
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
void main() { | |
final Builder builder = StudentBuilder(); | |
builder.buildFirstName('Tấn'); | |
builder.buildLastName('Mobile'); | |
Student student = builder.build(); | |
print(student.toString()); | |
} | |
abstract class Builder { | |
Builder buildFirstName(String firstName); | |
Builder buildLastName(String lastName); | |
Student build(); | |
} | |
class StudentBuilder implements Builder { | |
late String firstName; | |
late String lastName; | |
@override | |
Builder buildFirstName(String firstName) { | |
this.firstName = firstName; | |
return this; | |
} | |
@override | |
Builder buildLastName(String lastName) { | |
this.lastName = lastName; | |
return this; | |
} | |
@override | |
Student build() => Student(firstName, lastName); | |
} | |
class Student { | |
final String lastName; | |
final String firstName; | |
const Student(this.firstName, this.lastName); | |
@override | |
String toString(){ | |
return '$lastName $firstName'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment