Factory Method その1
単純移植
module FactoryMethod class IDCard def initialize(str) @owner = str end def use "#{@owner}のカード" end end class Factory def create(*arg) create_product(*arg) end end class IDCardFactory < Factory def create_product(str) IDCard.new(str) end end end factory = FactoryMethod::IDCardFactory.new card = factory.create("tarou") puts card.use
Rubyでのデザインパターン実装をいくつかやってみたが、単純移植の
ような実装方法では、型が無いため、使いどころに疑問を感じる。
Moduleを使えば、よりエレガントなRubyらしい実装になるのであろう。