Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active July 15, 2017 22:59
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/30834d210d4881a27f0a60eb581530f0 to your computer and use it in GitHub Desktop.
Save Sihui/30834d210d4881a27f0a60eb581530f0 to your computer and use it in GitHub Desktop.
Design Pattern: Simple Factory and Cheesecake Factory
def make_cheesecake(type)
cheesecake = nil
case type
when 'oreo'
cheesecake = OreoCheesecake.new
when 'coffee'
cheesecake = CoffeeCheesecake.new
when 'tiramisu'
cheesecake = TiramisuCheesecake.new
when 'smores'
cheesecake = SmoresCheesecake.new
when 'hazelnut'
cheesecake = HazelnutCheesecake.new
else
cheesecake = OriginalCheesecake.new
end
cheesecake.make_crust
cheesecake.add_layers
cheesecake.bake
cheesecake.refrigerate
cheesecake.add_toppings
cheesecake
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment