トップ «前の日記(2009-05-05) 最新 次の日記(2009-05-07)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2009-05-06 :-)

_ 朝ッ

0730 起床

_ おやつ

20090506_0.jpg

柏餅

_ 買い物

文教堂

4048677586

4086304600

4086304813

4840126666

_ [デザインパターン][Factory]Head First デザインパターンを写経する - 4章 Factory パターン

#!/usr/bin/ruby -Ks

class PizzaStore
  def orderPizza( type )
    @pizza
    @pizza = createPizza( type )
    @pizza.prepare
    @pizza.bake
    @pizza.cut
    @pizza.box
    @pizza
  end

  def createPizza( type )
  end
end

class NYPizzaStore < PizzaStore
  def createPizza( item )
    case item
    when "チーズ"
      NYStyleCheesePizza.new
##    when "野菜"
##      NYStyleVeggiePizza.new
##    when "クラム"
##      NYStyleClamPizza.new
##    when "ペパロニ"
##      NYStylePepperoniPizza.new
    else
      nil
    end
  end
end

class ChicagoPizzaStore < PizzaStore
  def createPizza( item )
    case item
    when "チーズ"
      ChicagoStyleCheesePizza.new
##    when "野菜"
##      ChicagoStyleVeggiePizza.new
##    when "クラム"Head First デザインパターンを写経する - 3章 Decorator パターン
##      ChicagoStyleClamPizza.new
##    when "ペパロニ"
##      ChicagoStylePepperoniPizza.new
    else
      nil
    end
  end
end

class CaliforniaPizzaStore < PizzaStore
  def createPizza( item )
    case item
    when "チーズ"
      CaliforniaStyleCheesePizza.new
    when "野菜"
      CaliforniaStyleVeggiePizza.new
    when "クラム"
      CaliforniaStyleClamPizza.new
    when "ペパロニ"
      CaliforniaStylePepperoniPizza.new
    else
      nil
    end
  end
end

class Pizza
  @name
  @dough
  @sauce
  @toppings

  def prepare
    puts "#{@name}を下処理"
    puts "生地をこねる..."
    puts "ソースを追加..."
    puts "トッピングを追加:"
    @toppings.each {|t|
      puts " #{t}"
    }
  end

  def bake
    puts "350度で25分間焼く"
  end

  def cut
    puts "ピザを扇形に切り分ける"
  end

  def box
    puts "PizzaStore の正式な箱にピザを入れる"
  end

  def getName
    @name
  end
end

class NYStyleCheesePizza < Pizza
  def initialize
    @name = "ニューヨークスタイルのソース&チーズピザ"
    @dough = "薄いクラスト生地"
    @sauce = "マリナラソース"
    @toppings = []
    @toppings << "粉レッジャーノチーズ"
  end
end

class ChicagoStyleCheesePizza < Pizza
  def initialize
    @name = "シカゴスタイルのディープディッシュチーズピザ"
    @dough = "極厚クラスト生地"
    @sauce = "プラムトマトソース"
    @toppings = []
    @toppings << "刻んだモッツァレラチーズ"
  end

  def cut
    puts "ピザを四角形に切り分ける"
  end
end

def main
  nyStore = NYPizzaStore.new
  chicagoStore = ChicagoPizzaStore.new
  pizza = nyStore.orderPizza( "チーズ" )
  puts "イーサンの注文は#{pizza.getName}"
  pizza = chicagoStore.orderPizza( "チーズ" )
  puts "ジョエルの注文は#{pizza.getName}"
end

main
% ./factory.rb
ニューヨークスタイルのソース&チーズピザを下処理
生地をこねる...
ソースを追加...
トッピングを追加:
 粉レッジャーノチーズ
350度で25分間焼く
ピザを扇形に切り分ける
PizzaStore の正式な箱にピザを入れる
イーサンの注文はニューヨークスタイルのソース&チーズピザ
シカゴスタイルのディープディッシュチーズピザを下処理
生地をこねる...
ソースを追加...
トッピングを追加:
 刻んだモッツァレラチーズ
350度で25分間焼く
ピザを四角形に切り分ける
PizzaStore の正式な箱にピザを入れる
ジョエルの注文はシカゴスタイルのディープディッシュチーズピザ

_ [デザインパターン][Abstract Factory]Head First デザインパターンを写経する - 4章 Abstract Factory パターン

素材クラスは途中で挫折したので全部は書いてない。

#!/usr/bin/ruby -Ks

module Veggies
  def to_s
  end
end

class Garlic
  include Veggies
  def to_s
    "Garlic"
  end
end

module Dough
  def to_s
  end
end

class ThinCrustDough
  include Dough
  def to_s
    "ThinCrustDough"
  end
end

class ThickCrustDough
  include Dough
  def to_s
    "ThickCrustDough"
  end
end

module PizzaIngredientFactory
  def createDough
  end
  def createSauce
  end
  def createCheese
  end
  def createVeggies
  end
  def createPapperoni
  end
  def createClam
  end
end

class NYPizzaIngredientFactory
  include PizzaIngredientFactory

  def createDough
    ThinCrustDough.new
  end
  def createSauce
#    MarinaraSauce.new
  end
  def createCheese
#    ReggianoCheese.new
  end
  def createVeggies
#    veggies = [ Garlic.new, Onion.new, Mushroom.new, RedPepper.new ]
  end
  def createPapperoni
#    SlicedPepperoni.new
  end
  def createClam
#    FreshClams.new
  end
end

class ChicagoPizzaIngredientFactory
  include PizzaIngredientFactory

  def createDough
    ThickCrustDough.new
  end
  def createSauce
#    PlumTomatoSauce.new
  end
  def createCheese
#    MozzarellaCheese.new
  end
  def createVeggies
#    veggies = [ BlackOlives.new, Spinach.new, Eggplant.new ]
  end
  def createPapperoni
#    SlicedPepperoni.new
  end
  def createClam
#    FrozenClams.new
  end
end


class PizzaStore
  def orderPizza( type )
    @pizza = createPizza( type )
    @pizza.prepare
    @pizza.bake
    @pizza.cut
    @pizza.box
    @pizza
  end

  def createPizza( type )
  end
end

class NYPizzaStore < PizzaStore
  def createPizza( item )
    pizza = nil
    ingredientFactory = NYPizzaIngredientFactory.new

    case item
    when "チーズ"
      pizza = CheesePizza.new( ingredientFactory )
      pizza.setName( "ニューヨークスタイルチーズピザ" )
##    when "野菜"
##      pizza = VeggiePizza( ingredientFactory )
##      pizza.setName( "ニューヨークスタイル野菜ピザ"
##    when "クラム"
##      pizza = ClamPizza( ingredientFactory )
##      pizza.setName( "ニューヨークスタイルクラムピザ"
##    when "ペパロニ"
##      pizza = PepperoniePizza( ingredientFactory )
##      pizza.setName( "ニューヨークスタイルペパロニピザ"
    else
      pizza = nil
    end

    pizza

  end
end

class ChicagoPizzaStore < PizzaStore
  def createPizza( item )
    pizza = nil
    ingredientFactory = ChicagoPizzaIngredientFactory.new

    case item
    when "チーズ"
      pizza = CheesePizza.new( ingredientFactory )
      pizza.setName( "ニューヨークスタイルチーズピザ" )
##    when "野菜"
##      pizza = VeggiePizza( ingredientFactory )
##      pizza.setName( "ニューヨークスタイル野菜ピザ"
##    when "クラム"
##      pizza = ClamPizza( ingredientFactory )
##      pizza.setName( "ニューヨークスタイルクラムピザ"
##    when "ペパロニ"
##      pizza = PepperoniePizza( ingredientFactory )
##      pizza.setName( "ニューヨークスタイルペパロニピザ"
    else
      pizza = nil
    end

    pizza

  end
end

class Pizza
  @name
  @dough
  @sauce
  @toppings = []
  @veggies = []
  @cheese
  @pepperoni
  @clam

  def prepare
  end

  def bake
    puts "350度で25分間焼く"
  end

  def cut
    puts "ピザを扇形に切り分ける"
  end

  def box
    puts "PizzaStore の正式な箱にピザを入れる"
  end

  def setName( name )
    @name = name
  end

  def getName
    @name
  end
end

class CheesePizza < Pizza
  @ingredientFactory

  def initialize( ingredientFactory )
    @ingredientFactory = ingredientFactory
  end

  def prepare
    puts "#{@name}を下処理"
    @dough = @ingredientFactory.createDough
    @sauce = @ingredientFactory.createSauce
    @cheese = @ingredientFactory.createCheese
  end
end

class ClamPizza < Pizza
  @ingredientFactory

  def initialize( ingredientFactory )
    @ingredientFactory = ingredientFactory
  end

  def prepare
    puts "#{@name}を下処理"
    @dough = @ingredientFactory.createDough
    @sauce = @ingredientFactory.createSauce
    @cheese = @ingredientFactory.createCheese
    @clam = @ingredientFactory.createClam
  end
end

def main
  nyStore = NYPizzaStore.new
  chicagoStore = ChicagoPizzaStore.new
  pizza = nyStore.orderPizza( "チーズ" )
  puts "イーサンの注文は#{pizza.getName}"
  pizza = chicagoStore.orderPizza( "チーズ" )
  puts "ジョエルの注文は#{pizza.getName}"
end

main
% ./abstractfactory.rb
ニューヨークスタイルチーズピザを下処理
350度で25分間焼く
ピザを扇形に切り分ける
PizzaStore の正式な箱にピザを入れる
イーサンの注文はニューヨークスタイルチーズピザ
ニューヨークスタイルチーズピザを下処理
350度で25分間焼く
ピザを扇形に切り分ける
PizzaStore の正式な箱にピザを入れる
ジョエルの注文はニューヨークスタイルチーズピザ

_ [おひる][ジェノヴェーゼ]おひる

ジェノヴェーゼぽいもの

_ [ゴーヤちゃんぷるー][]飯

ゴーヤちゃんぷるー