Last active
January 6, 2018 19:19
-
-
Save Sihui/6fcd821eecee83c10d0622da22af940b to your computer and use it in GitHub Desktop.
Design Pattern: Builder and Car
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 ElectronicCarBuilder | |
def build | |
car = '' | |
# 1. build car frame | |
car << "This is an electronic car\n" | |
# 2. add an engine | |
car << " with a electronic engine\n" | |
# 3. add front wheels | |
car << " with two front wheels\n" | |
# 4. add back wheels | |
car << " with two back wheels\n" | |
# 5. add dashboard | |
car << " with a dashboard showing current battery level\n" | |
# 6. add a energy source | |
car << " with a battery\n" | |
# return the car | |
car | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment