-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21ed672
commit 01b3033
Showing
10 changed files
with
396 additions
and
104 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
class Quackbehavior | ||
def quack | ||
end | ||
end | ||
|
||
class FlyBehavior | ||
def fly | ||
end | ||
end | ||
|
||
class CanNotFly < FlyBehavior | ||
def fly | ||
puts "I can not fly" | ||
end | ||
end | ||
|
||
class CanFly < FlyBehavior | ||
def fly | ||
puts "Im Fliying" | ||
end | ||
end | ||
|
||
class CanQuack < Quackbehavior | ||
def quack | ||
puts "Quack!" | ||
end | ||
end | ||
|
||
class CanNotQuack < Quackbehavior | ||
def quack | ||
puts "I can not quack!" | ||
end | ||
end | ||
|
||
|
||
class Duck | ||
@flybehavior = FlyBehavior.new | ||
@quackbehavior = Quackbehavior.new | ||
def display | ||
end | ||
def fly | ||
@flybehavior.fly | ||
end | ||
def quack | ||
@quackbehavior.quack | ||
end | ||
end | ||
|
||
|
||
|
||
class MallarDuck < Duck | ||
def initialize | ||
@flybehavior = CanFly.new | ||
@quackbehavior = CanQuack.new | ||
end | ||
def display | ||
puts "I am MallarDuck" | ||
end | ||
end | ||
|
||
|
||
class RedheadDuck < Duck | ||
def initialize | ||
@flybehavior = CanFly.new | ||
@quackbehavior = CanQuack.new | ||
end | ||
def display | ||
puts "I am RedheadDuck" | ||
end | ||
end | ||
|
||
class RubberDuck < Duck | ||
def initialize | ||
@flybehavior = CanNotFly.new | ||
@quackbehavior = CanQuack.new | ||
end | ||
def display | ||
puts "I am Rubber Duck" | ||
end | ||
end | ||
|
||
class DecoyDuck < Duck | ||
def initialize | ||
@flybehavior = CanNotFly.new | ||
@quackbehavior = CanNotQuack.new | ||
end | ||
def display | ||
puts "I am Decoy Duck" | ||
end | ||
end | ||
|
||
puts "---------DUCK_SIMULATOR PROBLEM-----------" | ||
mallarDuck = MallarDuck.new | ||
redheadDuck = RedheadDuck.new | ||
rubberDuck = RubberDuck.new | ||
decoyDuck = DecoyDuck.new | ||
|
||
mallarDuck.display | ||
mallarDuck.fly | ||
mallarDuck.quack | ||
puts "-------------------------------" | ||
|
||
redheadDuck.display | ||
redheadDuck.fly | ||
mallarDuck.quack | ||
puts "--------------------------------" | ||
|
||
rubberDuck.display | ||
rubberDuck.fly | ||
rubberDuck.quack | ||
puts "--------------------------------" | ||
|
||
decoyDuck.display | ||
decoyDuck.fly | ||
decoyDuck.quack |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
|
||
Abstract Factory and Factory Method Pattern - PizzaStore | ||
Decorator Pattern - Starbuzz | ||
Strategy Pattern - DuckSimulator | ||
|
||
Online Workspace: https://repl.it/@OscarMichel1/DesignPatternProblems | ||
Copyright (C) 2018 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
# abstract-factory.rb | ||
# 1. common type interface | ||
class Pizza | ||
@cheese = String.new | ||
@pina = String.new | ||
@otrosIngredientes = String.new | ||
@masa = String.new | ||
@temperaturaHorno = String.new | ||
def preparar | ||
puts "Preparar la masa estilo: " + @masa | ||
puts "Prepara/Agregar salsa" | ||
puts "Agregar ingredientes:" | ||
if(@cheese.length > 0) | ||
puts @cheese | ||
end | ||
if(@pina.length > 0) | ||
puts @pina | ||
end | ||
if(@otrosIngredientes.length > 0) | ||
puts @otrosIngredientes | ||
end | ||
puts "Hornear a temperatura: " + @temperaturaHorno | ||
puts "Cortar la pizza en rebanadas" | ||
puts "Poner la pizza en su caja" | ||
end | ||
end | ||
|
||
#factory-method | ||
class PizzaStore | ||
@pizza = Pizza.new | ||
def createPizza | ||
end | ||
def orderPizza | ||
@pizza.preparar | ||
end | ||
end | ||
|
||
|
||
class PizzaIngredientFactory | ||
def createCheese | ||
end | ||
def createPina | ||
end | ||
def createMasa | ||
end | ||
def temperature | ||
end | ||
end | ||
|
||
class CentralCityIngredientFactory < PizzaIngredientFactory | ||
def createCheese | ||
"-Cheese de Central City!!" | ||
end | ||
def createPina | ||
"-Pina de Central City!!" | ||
end | ||
def createMasa | ||
"Masa de Central City!!" | ||
end | ||
def temperature | ||
"100" | ||
end | ||
end | ||
|
||
class StarCityIngredientFactory < PizzaIngredientFactory | ||
def createCheese | ||
"-Cheese de Star City !!" | ||
end | ||
def createPina | ||
"-Piña de Star City !!" | ||
end | ||
def createMasa | ||
"Masa de Star City!!" | ||
end | ||
def temperature | ||
"99" | ||
end | ||
end | ||
|
||
|
||
class MetropolisIngredientFactory < PizzaIngredientFactory | ||
def createCheese | ||
"-Cheese de MetroPolis!!" | ||
end | ||
def createPina | ||
"-Piña de MetroPolis!!" | ||
end | ||
def createMasa | ||
"Masa de Metropolis!!" | ||
end | ||
def temperature | ||
"105" | ||
end | ||
end | ||
|
||
|
||
class GothamIngredientFactory < PizzaIngredientFactory | ||
def createCheese | ||
"-Cheese de Gotham!!" | ||
end | ||
def createPina | ||
"-Piña de Gotham!!" | ||
end | ||
def createMasa | ||
"Masa de Gotham!!" | ||
end | ||
def temperature | ||
"110" | ||
end | ||
end | ||
|
||
|
||
# 2. implementations of common type interface | ||
class Queso < Pizza | ||
def initialize(ingredientFactory) | ||
@cheese = ingredientFactory.createCheese | ||
@pina = "" | ||
@otrosIngredientes = "" | ||
@masa = ingredientFactory.createMasa | ||
@temperaturaHorno = ingredientFactory.temperature | ||
end | ||
end | ||
|
||
class Peperoni < Pizza | ||
def initialize(ingredientFactory) | ||
@cheese = ingredientFactory.createCheese | ||
@pina = "" | ||
@otrosIngredientes = "-Pepperoni" | ||
@masa = ingredientFactory.createMasa | ||
@temperaturaHorno = ingredientFactory.temperature | ||
end | ||
end | ||
|
||
class Hawaiana < Pizza | ||
def initialize(ingredientFactory) | ||
@cheese = ingredientFactory.createCheese | ||
@pina = ingredientFactory.createPina | ||
@otrosIngredientes = "-Jamon" | ||
@masa = ingredientFactory.createMasa | ||
@temperaturaHorno = ingredientFactory.temperature | ||
end | ||
end | ||
|
||
class Alcachofas < Pizza | ||
def initialize(ingredientFactory) | ||
@cheese = ingredientFactory.createCheese | ||
@pina = "" | ||
@otrosIngredientes = "-Alcachofas" | ||
@masa = ingredientFactory.createMasa | ||
@temperaturaHorno = ingredientFactory.temperature | ||
end | ||
end | ||
|
||
# 3. Creator class for various types | ||
#Factories | ||
class CentralCityStore < PizzaStore | ||
def createPizza(type) | ||
ingredientFactory = CentralCityIngredientFactory.new | ||
case type | ||
when 'Queso' | ||
@pizza = Queso.new(ingredientFactory) | ||
when 'Peperoni' | ||
@pizza = Peperoni.new(ingredientFactory) | ||
when 'Hawaiana' | ||
@pizza = Hawaiana.new(ingredientFactory) | ||
when 'Alcachofas' | ||
@pizza = Alcachofas.new(ingredientFactory) | ||
else | ||
end | ||
end | ||
end | ||
|
||
class StarCityStore < PizzaStore | ||
def createPizza(type) | ||
ingredientFactory = StarCityIngredientFactory.new | ||
case type | ||
when 'Queso' | ||
@pizza = Queso.new(ingredientFactory) | ||
when 'Peperoni' | ||
@pizza = Peperoni.new(ingredientFactory) | ||
when 'Hawaiana' | ||
@pizza = Hawaiana.new(ingredientFactory) | ||
when 'Alcachofas' | ||
@pizza = Alcachofas.new(ingredientFactory) | ||
else | ||
end | ||
end | ||
end | ||
|
||
class MetropolisStore < PizzaStore | ||
def createPizza(type) | ||
ingredientFactory = MetropolisIngredientFactory.new | ||
case type | ||
when 'Queso' | ||
@pizza = Queso.new(ingredientFactory) | ||
when 'Peperoni' | ||
@pizza = Peperoni.new(ingredientFactory) | ||
when 'Hawaiana' | ||
@pizza = Hawaiana.new(ingredientFactory) | ||
when 'Alcachofas' | ||
@pizza = Alcachofas.new(ingredientFactory) | ||
else | ||
end | ||
end | ||
end | ||
|
||
class GothamStore < PizzaStore | ||
def createPizza(type) | ||
ingredientFactory = GothamIngredientFactory.new | ||
case type | ||
when 'Queso' | ||
@pizza = Queso.new(ingredientFactory) | ||
when 'Peperoni' | ||
@pizza = Peperoni.new(ingredientFactory) | ||
when 'Hawaiana' | ||
@pizza = Hawaiana.new(ingredientFactory) | ||
when 'Alcachofas' | ||
@pizza = Alcachofas.new(ingredientFactory) | ||
else | ||
end | ||
end | ||
end | ||
|
||
puts "------------PIZZASTORE PROBLEM--------------" | ||
myStore = CentralCityStore.new | ||
myStore.createPizza('Queso') | ||
myStore.orderPizza | ||
puts "-------------------------------" | ||
myStore = StarCityStore.new | ||
myStore.createPizza('Peperoni') | ||
myStore.orderPizza | ||
puts "-------------------------------" | ||
myStore = MetropolisStore.new | ||
myStore.createPizza('Hawaiana') | ||
myStore.orderPizza | ||
puts "-------------------------------" | ||
myStore = GothamStore.new | ||
myStore.createPizza('Alcachofas') | ||
myStore.orderPizza | ||
|
||
puts "\n \n" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.