Last active
September 1, 2015 15:55
-
-
Save jpotts18/a5c202aee473fded6721 to your computer and use it in GitHub Desktop.
Ruby Factory Pattern
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 PizzaFactory | |
def self.create_pizza(type) | |
if type == 'Pepperoni' | |
return PepperoniPizza.new | |
if type == 'Greek' | |
return GreekPizza.new | |
end | |
end | |
end | |
class Pizza | |
def bake | |
puts "Baking pizza..." | |
end | |
def package | |
puts "Baking pizza..." | |
end | |
end | |
# Concrete implementations | |
class PepperoniPizza < Pizza | |
def bake | |
puts "Baking Pepperoni pizza" | |
end | |
def package | |
puts "Packaging Pepperoni pizza" | |
end | |
end | |
class GreekPizza < Pizza | |
def bake | |
puts "Baking Greek pizza" | |
end | |
def package | |
puts "Baking Greek pizza" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment