Factory Method その2
module FactoryMethod class IDCard def initialize(str) @owner = str end def use "#{@owner}のカード" end end module Factory def create(*arg) product(*arg) end end class IDCardFactory include Factory def product(str) IDCard.new(str) end end end factory = FactoryMethod::IDCardFactory.new card = factory.create("tarou") puts card.use
前回からFactoryをmoduleにしただけです。
Factoryは、includeしたクラスにproductメソッド
が実装されている事を期待します。