Last active
January 11, 2018 04:41
-
-
Save Sihui/19cbbf514c35e27408a05844df2f4e96 to your computer and use it in GitHub Desktop.
Design Pattern: Builder and Car
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
class SportsCarBuilder | |
def build | |
car = '' | |
# 1. build car frame | |
car << "This is a sport car\n" | |
# 2. add an engine | |
car << " with a powerful engine\n" | |
# 3. add front wheels | |
car << " with two front wheels suitable for mountain paths\n" | |
# 4. add back wheels | |
car << " with two back wheels suitable for mountain paths\n" | |
# 5. add dashboard | |
car << " with a fancy sporty dashboard\n" | |
# 6. add a energy source | |
car << " with a big fuel tank\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