Паттерны / Порождающие паттерны
image

# concrete product A1
class ProductA1
    def testA() 
        puts "test A1"
    end
end

# concrete product A2
class ProductA2
    def testA() 
        puts "test A2"
    end
end

# concrete product B1
class ProductB1
    def testB() 
        puts "test B1"
    end
end

# concrete product B2
class ProductB2
    def testB() 
        puts "test B2"
    end
end

# concrete factory 1
class Factory1
    def createA() 
        return ProductA1.new
    end
    def createB() 
        return ProductB1.new
    end
end

# concrete factory 2
class Factory2
    def createA() 
        return ProductA2.new
    end
    def createB() 
        return ProductB2.new
    end
end

# client code
def testFactory(factory) 
    productA = factory.createA()
    productB = factory.createB()
    productA.testA()
    productB.testB()
end

testFactory(Factory1.new)
# printed: test A1
#          test B1
testFactory(Factory2.new)
# printed: test A2
#          test B2