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/a9398e3cf9c368499b1bb9cb30f04f8d to your computer and use it in GitHub Desktop.
Save Sihui/a9398e3cf9c368499b1bb9cb30f04f8d to your computer and use it in GitHub Desktop.
Design Pattern: Builder and Car
class ElectronicCarBuilder
attr_reader :car
def initialize
@car = ''
end
def build_car_frame
car << "This is an electronic car\n"
end
def add_engine
car << " with a electronic engine\n"
end
def add_front_wheels
car << " with two front wheels\n"
end
def add_back_wheels
car << " with two back wheels\n"
end
def add_dashboard
car << " with a dashboard showing current battery level\n"
end
def add_energy_source
car << " with a battery\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment