Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active January 6, 2018 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sihui/3ad0b1eb45d8f9afeba9ee5d7f2206b6 to your computer and use it in GitHub Desktop.
Save Sihui/3ad0b1eb45d8f9afeba9ee5d7f2206b6 to your computer and use it in GitHub Desktop.
Design Pattern: Builder and Car
class StandardCarBuilder
def build
car = ''
# 1. build car frame
car << "This is a standard car\n"
# 2. add an engine
car << " with an 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\n"
# 6. add a energy source
car << " with a 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